Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_commandline supports polars engine #1356

Merged
merged 58 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
862c7dd
add make_clean_names function that can be applied to polars
Apr 19, 2024
01531cc
add examples for make_clean_names
Apr 20, 2024
0fb440e
changelog
Apr 20, 2024
5e944b2
limit import location for polars
Apr 20, 2024
501d9c6
limit import location for polars
Apr 20, 2024
9506832
fix polars in environment-dev.yml
Apr 20, 2024
1ae8edd
install polars in doctest
Apr 20, 2024
3b1829b
limit polars imports - user should have polars already installed
Apr 20, 2024
52fd80c
use subprocess.run
Apr 20, 2024
2dce78b
add subprocess.devnull to docstrings
Apr 20, 2024
37b3feb
add subprocess.devnull to docstrings
Apr 20, 2024
0953f2d
add subprocess.devnull to docstrings
Apr 20, 2024
d7c71b6
add subprocess.devnull to docstrings
Apr 20, 2024
40b8502
add os.devnull
Apr 20, 2024
4f11d09
add polars as requirement for docs
Apr 20, 2024
54b179c
add polars to tests requirements
Apr 20, 2024
25b39b9
delete irrelevant folder
Apr 20, 2024
a09f34b
changelog
Apr 20, 2024
1b375f8
create submodule for polars
Apr 21, 2024
799532f
fix doctests
Apr 21, 2024
dbce4b9
fix tests; add polars to documentation
Apr 21, 2024
1c642e6
fix tests; add polars to documentation
Apr 21, 2024
407d21b
import janitor.polars
Apr 21, 2024
aedfc65
control docs output for polars submodule
Apr 21, 2024
db9b486
exclude functions in docs rendering
Apr 21, 2024
6a91e67
exclude functions in docs rendering
Apr 21, 2024
7a88078
show_submodules=true
Apr 21, 2024
6d7885e
fix docstring rendering for polars
Apr 21, 2024
944fa02
Expression -> expression
Apr 21, 2024
b9aefaa
Merge dev into samukweku/polars_clean_names
ericmjl Apr 23, 2024
e9c370a
rename functions.py
Apr 23, 2024
ee66d2a
pivot_longer implemented for polars
Apr 29, 2024
959b082
changelog
Apr 30, 2024
3177503
keep changes related only to pivot_longer
Apr 30, 2024
ee899b2
pd -> pl
Apr 30, 2024
8ea9b71
pd -> pl
Apr 30, 2024
d12ae1a
df.pivot_longer -> df.janitor.pivot_longer
Apr 30, 2024
652f3e3
df.pivot_longer -> df.janitor.pivot_longer
Apr 30, 2024
9b9c1a9
pd -> pl
Apr 30, 2024
69c273f
pd -> pl
Apr 30, 2024
b3391e8
add >>> df
Apr 30, 2024
4ffaac5
add >>> df
Apr 30, 2024
1de57bb
keep changes related only to polars pivot_longer
Apr 30, 2024
e495790
add polars support to read_commandline
May 1, 2024
a5c331a
remove irrelevant files
May 1, 2024
4d9c35f
minor edit to docs
May 1, 2024
c5a4ec0
Merge dev into samukweku/polars_read_commandline
ericmjl May 6, 2024
a1c63cc
Merge dev into samukweku/polars_read_commandline
ericmjl May 10, 2024
c6abea9
Merge dev into samukweku/polars_read_commandline
ericmjl May 19, 2024
b66edaa
Merge dev into samukweku/polars_read_commandline
ericmjl May 23, 2024
5b5dde6
Merge dev into samukweku/polars_read_commandline
ericmjl May 27, 2024
cee6d58
Merge dev into samukweku/polars_read_commandline
ericmjl Jun 2, 2024
2f05526
test(io): Parameterize test_read_commandline with engine
ericmjl Jun 2, 2024
a84fc38
test(io): update default parameter in test_read_commandline
ericmjl Jun 2, 2024
c496661
Merge dev into samukweku/polars_read_commandline
ericmjl Jun 3, 2024
3463238
refactor(tests/io): simplify `test_read_commandline` by removing engi…
ericmjl Jun 3, 2024
9fc110b
Merge dev into samukweku/polars_read_commandline
ericmjl Jun 4, 2024
d1f1a1e
Merge dev into samukweku/polars_read_commandline
ericmjl Jun 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]
- [ENH] `read_commandline` function now supports polars - Issue #1352

- [ENH] Improved performance for non-equi joins when using numba - @samukweku PR #1341
- [ENH] Added a `clean_names` method for polars - it can be used to clean the column names, or clean column values . Issue #1343 @samukweku
Expand Down
28 changes: 22 additions & 6 deletions janitor/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def read_csvs(
return dfs_dict


def read_commandline(cmd: str, **kwargs: Any) -> pd.DataFrame:
def read_commandline(cmd: str, engine="pandas", **kwargs: Any) -> Mapping:
"""Read a CSV file based on a command-line command.

For example, you may wish to run the following command on `sep-quarter.csv`
Expand All @@ -111,26 +111,42 @@ def read_commandline(cmd: str, **kwargs: Any) -> pd.DataFrame:
```

This function assumes that your command line command will return
an output that is parsable using `pandas.read_csv` and StringIO.
We default to using `pd.read_csv` underneath the hood.
Keyword arguments are passed through to read_csv.
an output that is parsable using the relevant engine and StringIO.
This function defaults to using `pd.read_csv` underneath the hood.
Keyword arguments are passed through as-is.

Args:
cmd: Shell command to preprocess a file on disk.
engine: DataFrame engine to process the output of the shell command.
Currently supports both pandas and polars.
**kwargs: Keyword arguments that are passed through to
`pd.read_csv()`.
the engine's csv reader.


Returns:
A pandas DataFrame parsed from the stdout of the underlying
A DataFrame parsed from the stdout of the underlying
shell.
"""

check("cmd", cmd, [str])
if engine not in {"pandas", "polars"}:
raise ValueError("engine should be either pandas or polars.")
# adding check=True ensures that an explicit, clear error
# is raised, so that the user can see the reason for the failure
outcome = subprocess.run(
cmd, shell=True, capture_output=True, text=True, check=True
)
if engine == "polars":
try:
import polars as pl
except ImportError:
import_message(
submodule="polars",
package="polars",
conda_channel="conda-forge",
pip_install=True,
)
return pl.read_csv(StringIO(outcome.stdout), **kwargs)
return pd.read_csv(StringIO(outcome.stdout), **kwargs)


Expand Down
Loading