diff --git a/python/pyarrow/feather.py b/python/pyarrow/feather.py index 8fe0126ee2349..a0547949c9158 100644 --- a/python/pyarrow/feather.py +++ b/python/pyarrow/feather.py @@ -204,7 +204,8 @@ def write_feather(df, dest, compression=None, compression_level=None, raise -def read_feather(source, columns=None, use_threads=True, memory_map=False): +def read_feather(source, columns=None, use_threads=True, + memory_map=False, **kwargs): """ Read a pandas.DataFrame from Feather format. To read as pyarrow.Table use feather.read_table. @@ -222,6 +223,8 @@ def read_feather(source, columns=None, use_threads=True, memory_map=False): reading from Feather format. memory_map : boolean, default False Use memory mapping when opening file on disk, when source is a str. + **kwargs + Additional keyword arguments passed on to `pyarrow.Table.to_pandas`. Returns ------- @@ -230,7 +233,7 @@ def read_feather(source, columns=None, use_threads=True, memory_map=False): _check_pandas_version() return (read_table( source, columns=columns, memory_map=memory_map, - use_threads=use_threads).to_pandas(use_threads=use_threads)) + use_threads=use_threads).to_pandas(use_threads=use_threads, **kwargs)) def read_table(source, columns=None, memory_map=False, use_threads=True): diff --git a/python/pyarrow/tests/test_feather.py b/python/pyarrow/tests/test_feather.py index 97696fa6a92f5..fcd9628f76cb6 100644 --- a/python/pyarrow/tests/test_feather.py +++ b/python/pyarrow/tests/test_feather.py @@ -838,3 +838,25 @@ def test_preserve_index_pandas(version): expected = df _check_pandas_roundtrip(df, expected, version=version) + + +@pytest.mark.pandas +def test_feather_datetime_resolution_arrow_to_pandas(tempdir): + # ARROW-17192 - ensure timestamp_as_object=True (together with other + # **kwargs) can be passed in read_feather to to_pandas. + + from datetime import datetime + df = pd.DataFrame({"date": [ + datetime.fromisoformat("1654-01-01"), + datetime.fromisoformat("1920-01-01"), ], + }) + write_feather(df, tempdir / "test_resolution.feather") + + expected_0 = datetime.fromisoformat("1654-01-01") + expected_1 = datetime.fromisoformat("1920-01-01") + + result = read_feather(tempdir / "test_resolution.feather", + timestamp_as_object=True) + + assert expected_0 == result['date'][0] + assert expected_1 == result['date'][1]