From 1de7c4bc693b52d94e71a52fa6f03a28631a70b6 Mon Sep 17 00:00:00 2001 From: aidoskanapyanov Date: Tue, 23 Jan 2024 11:13:05 +0600 Subject: [PATCH 1/3] TST: Interchange implementation for timestamp[ns][pyarrow] --- pandas/tests/interchange/test_impl.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/interchange/test_impl.py b/pandas/tests/interchange/test_impl.py index 2bc488fbb1dd1..df47be469f59e 100644 --- a/pandas/tests/interchange/test_impl.py +++ b/pandas/tests/interchange/test_impl.py @@ -295,6 +295,17 @@ def test_multi_chunk_pyarrow() -> None: pd.api.interchange.from_dataframe(table, allow_copy=False) +def test_timestamp_ns_pyarrow(): + # gh 56712 + df = pd.Series( + [datetime(2000, 1, 1, 1, 1, 1)], dtype="timestamp[ns][pyarrow]", name="col0" + ).to_frame() + dfi = df.__dataframe__() + result = pd.api.interchange.from_dataframe(dfi) + result["col0"] = result["col0"].astype("timestamp[ns][pyarrow]") + tm.assert_frame_equal(df, result) + + @pytest.mark.parametrize("tz", ["UTC", "US/Pacific"]) def test_datetimetzdtype(tz, unit): # GH 54239 From 1a2b2d7374b86779044e61b92ba610fbfd6bf1ec Mon Sep 17 00:00:00 2001 From: aidoskanapyanov Date: Mon, 29 Jan 2024 09:29:36 +0600 Subject: [PATCH 2/3] Check timestamp explicitly --- pandas/tests/interchange/test_impl.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pandas/tests/interchange/test_impl.py b/pandas/tests/interchange/test_impl.py index 8d0a124b90ff1..5bfcf40c1682c 100644 --- a/pandas/tests/interchange/test_impl.py +++ b/pandas/tests/interchange/test_impl.py @@ -294,14 +294,26 @@ def test_multi_chunk_pyarrow() -> None: def test_timestamp_ns_pyarrow(): - # gh 56712 + # GH 56712 + timestamp_args = { + "year": 2000, + "month": 1, + "day": 1, + "hour": 1, + "minute": 1, + "second": 1, + } df = pd.Series( - [datetime(2000, 1, 1, 1, 1, 1)], dtype="timestamp[ns][pyarrow]", name="col0" + [datetime(**timestamp_args)], + dtype="timestamp[ns][pyarrow]", + name="col0", ).to_frame() + dfi = df.__dataframe__() - result = pd.api.interchange.from_dataframe(dfi) - result["col0"] = result["col0"].astype("timestamp[ns][pyarrow]") - tm.assert_frame_equal(df, result) + result = pd.api.interchange.from_dataframe(dfi)["col0"].item() + + expected = pd.Timestamp(**timestamp_args) + assert result == expected @pytest.mark.parametrize("tz", ["UTC", "US/Pacific"]) From a0e6daf2c86a52de358a11f17dac937e4c9acda6 Mon Sep 17 00:00:00 2001 From: aidoskanapyanov Date: Mon, 29 Jan 2024 15:26:16 +0600 Subject: [PATCH 3/3] Use pytest.importorskip --- pandas/tests/interchange/test_impl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/interchange/test_impl.py b/pandas/tests/interchange/test_impl.py index 5bfcf40c1682c..aeee98f5a125e 100644 --- a/pandas/tests/interchange/test_impl.py +++ b/pandas/tests/interchange/test_impl.py @@ -295,6 +295,7 @@ def test_multi_chunk_pyarrow() -> None: def test_timestamp_ns_pyarrow(): # GH 56712 + pytest.importorskip("pyarrow", "11.0.0") timestamp_args = { "year": 2000, "month": 1,