-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Provide examples of using read_parquet #49739 #54150
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3cadf3
DOC: Provide examples of using read_parquet #49739
694700e
DOC: Provide examples of using read_parquet #49739
0ec5d45
DOC: Provide examples of using read_parquet #49739 (with minor fixes)
bc3c5d4
DOC: Provide examples of using read_parquet #49739
4bb7434
DOC: Provide examples of using read_parquet #49739 - fix formatting f…
b2d3a5d
DOC: Provide examples of using read_parquet #49739 - removed read_par…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -556,7 +556,65 @@ def read_parquet( | |
Returns | ||
------- | ||
DataFrame | ||
|
||
See Also | ||
-------- | ||
DataFrame.to_parquet : Create a parquet object that serializes a DataFrame. | ||
|
||
Examples | ||
-------- | ||
>>> import pandas as pd | ||
>>> original_df = pd.DataFrame( | ||
... {{"foo": range(5), "bar": range(5, 10)}} | ||
... ) | ||
>>> original_df | ||
foo bar | ||
0 0 5 | ||
1 1 6 | ||
2 2 7 | ||
3 3 8 | ||
4 4 9 | ||
>>> df_parquet_bytes = original_df.to_parquet() | ||
>>> from io import BytesIO | ||
>>> restored_df = pd.read_parquet(BytesIO(df_parquet_bytes)) | ||
>>> restored_df | ||
foo bar | ||
0 0 5 | ||
1 1 6 | ||
2 2 7 | ||
3 3 8 | ||
4 4 9 | ||
>>> restored_df.equals(original_df) | ||
True | ||
>>> restored_bar = pd.read_parquet(BytesIO(df_parquet_bytes), columns=["bar"]) | ||
>>> restored_bar | ||
bar | ||
0 5 | ||
1 6 | ||
2 7 | ||
3 8 | ||
4 9 | ||
>>> restored_bar.equals(original_df[['bar']]) | ||
True | ||
|
||
The function uses `kwargs` that are passed directly to the engine. | ||
In the following example, we use the `filters` argument of the pyarrow | ||
engine to filter the rows of the DataFrame. | ||
|
||
Since `pyarrow` is the default engine, we can omit the `engine` argument. | ||
Note that the `filters` argument is implemented by the `pyarrow` engine, | ||
which can benefit from multithreading and also potentially be more | ||
economical in terms of memory. | ||
|
||
>>> sel = [("foo", ">", 2)] | ||
>>> restored_part = pd.read_parquet(BytesIO(df_parquet_bytes), filters=sel) | ||
>>> restored_part | ||
foo bar | ||
0 3 8 | ||
1 4 9 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No blank line here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed and pushed. Tested locally with |
||
""" | ||
|
||
impl = get_engine(engine) | ||
|
||
if use_nullable_dtypes is not lib.no_default: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed (it fails a check).