Skip to content

Commit

Permalink
GH-35250: [Python] Add test for datetime column conversion to pandas (#…
Browse files Browse the repository at this point in the history
…35546)

### Rationale for this change
In pandas version 2.1.0 `__from_arrow__` method has been implemented for `DatetimeTZDtype` extension type. See pandas-dev/pandas#52201.

Due to this change, the conversion from pyarrow table column with datetime uses the newly implemented `__from_arrow__` method for the pandas dtype and `pandas_api.series` to construct the pandas series. We had to pass the name in the `pandas_api.series` also, to fix failing tests in #35248.

This PR adds explicit test for this change.
* Closes: #35250

Authored-by: Alenka Frim <frim.alenka@gmail.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
  • Loading branch information
AlenkaF committed Jun 1, 2023
1 parent e44bcaf commit 3456131
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4816,3 +4816,17 @@ def test_unhashable_map_keys_with_pydicts():
for tup1, tup2 in zip(row1, row2):
assert np.array_equal(tup1[0], tup2[0])
assert tup1[1] == tup2[1]


def test_column_conversion_for_datetime():
# GH-35235
# pandas implemented __from_arrow__ for DatetimeTZDtype
# https://github.com/pandas-dev/pandas/pull/52201
arr = pd.Series(pd.date_range("2012", periods=2, tz="Europe/Brussels"),
name="datetime_column")
table = pa.table({"datetime_column": pa.array(arr)})
table_col = table.column("datetime_column")

result = table_col.to_pandas()
assert result.name == "datetime_column"
tm.assert_series_equal(result, arr)

0 comments on commit 3456131

Please sign in to comment.