-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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 all commits
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 |
---|---|---|
|
@@ -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): | ||
|
@@ -71,6 +73,10 @@ def test_basic(self): | |
"dtns": pd.date_range("20130101", periods=3, freq="ns"), | ||
} | ||
) | ||
if pyarrow_version >= LooseVersion("0.16.1.dev"): | ||
df["periods"] = pd.period_range("2013", freq="M", periods=3) | ||
df["timedeltas"] = pd.timedelta_range("1 day", periods=3) | ||
df["intervals"] = pd.interval_range(0, 3, 3) | ||
|
||
assert df.dttz.dtype.tz.zone == "US/Eastern" | ||
self.check_round_trip(df) | ||
|
@@ -102,8 +108,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 +154,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.
any reason not to make these explicit?
Uh oh!
There was an error while loading. Please reload this page.
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.
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)