-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: update feather IO for pyarrow 0.17 / Feather V2 #33422
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2058,18 +2058,24 @@ def to_stata( | |
writer.write_file() | ||
|
||
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path") | ||
def to_feather(self, path) -> None: | ||
def to_feather(self, path, **kwargs) -> None: | ||
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. any reason not to make these explicit? 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.
It might change with the pyarrow version, needing us to each time update if other keywords get added. Passing through kwargs makes this more "future-robust". But I could make the ones that there are now explicit. However, that also means that we need to check the pyarrow version to give a nice error message to say which keyword is not yet supported with the older pyarrow versions (which is of course not that difficult) |
||
""" | ||
Write out the binary feather-format for DataFrames. | ||
Write a DataFrame to the binary Feather format. | ||
|
||
Parameters | ||
---------- | ||
path : str | ||
String file path. | ||
**kwargs : | ||
Additional keywords passed to :func:`pyarrow.feather.write_feather`. | ||
Starting with pyarrow 0.17, this includes the `compression`, | ||
`compression_level`, `chunksize` and `version` keywords. | ||
|
||
.. versionadded:: 1.1.0 | ||
""" | ||
from pandas.io.feather_format import to_feather | ||
|
||
to_feather(self, path) | ||
to_feather(self, path, **kwargs) | ||
|
||
@Appender( | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
import numpy as np | ||
import pytest | ||
|
||
import pandas.util._test_decorators as td | ||
|
||
import pandas as pd | ||
import pandas._testing as tm | ||
|
||
|
@@ -27,15 +29,15 @@ def check_error_on_write(self, df, exc): | |
with tm.ensure_clean() as path: | ||
to_feather(df, path) | ||
|
||
def check_round_trip(self, df, expected=None, **kwargs): | ||
def check_round_trip(self, df, expected=None, write_kwargs={}, **read_kwargs): | ||
|
||
if expected is None: | ||
expected = df | ||
|
||
with tm.ensure_clean() as path: | ||
to_feather(df, path) | ||
to_feather(df, path, **write_kwargs) | ||
|
||
result = read_feather(path, **kwargs) | ||
result = read_feather(path, **read_kwargs) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_error(self): | ||
|
@@ -102,8 +104,8 @@ def test_read_columns(self): | |
|
||
def test_unsupported_other(self): | ||
|
||
# period | ||
df = pd.DataFrame({"a": pd.period_range("2013", freq="M", periods=3)}) | ||
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. Since feather now exactly maps to the Arrow memory, periods are now supported (since Period is supported in the pandas->pyarrow.Table conversion) 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. that answers my question above, never mind |
||
# mixed python objects | ||
df = pd.DataFrame({"a": ["a", 1, 2.0]}) | ||
# Some versions raise ValueError, others raise ArrowInvalid. | ||
self.check_error_on_write(df, Exception) | ||
|
||
|
@@ -148,3 +150,8 @@ def test_path_localpath(self): | |
df = tm.makeDataFrame().reset_index() | ||
result = tm.round_trip_localpath(df.to_feather, pd.read_feather) | ||
tm.assert_frame_equal(df, result) | ||
|
||
@td.skip_if_no("pyarrow", min_version="0.16.1.dev") | ||
def test_passthrough_keywords(self): | ||
df = tm.makeDataFrame().reset_index() | ||
self.check_round_trip(df, write_kwargs=dict(version=1)) |
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.
Missing a word here. Maybe
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.
for my edification, does this mean that PeriodIndex or Series[Period] is supported? If so, is that a change from the older version?