jorisvandenbossche commented on code in PR #14531:
URL: https://github.com/apache/arrow/pull/14531#discussion_r1017750606
##########
python/pyarrow/tests/test_pandas.py:
##########
@@ -4498,3 +4498,18 @@ def test_does_not_mutate_timedelta_dtype():
t.to_pandas()
assert np.dtype(np.timedelta64) == expected
+
+
+def test_read_feather_does_not_mutate_timedelta():
+ # ARROW-17893: dataframe with timedelta and a list of dictionary
+ # also with timedelta produces wrong result with to_pandas
+
+ from datetime import timedelta
+ timedelta_1 = [{"timedelta_1": timedelta(seconds=12, microseconds=1)}]
+ timedelta_2 = [timedelta(hours=3, minutes=40, seconds=23)]
+ data = {"timedelta_1": timedelta_1, "timedelta_2": timedelta_2, }
+
+ table = pa.Table.from_pydict(data)
+ df = table.to_pandas()
+
+ assert df["timedelta_2"].item() == timedelta_2[0]
Review Comment:
```suggestion
assert df["timedelta_2"][0].to_pytimedelta() == timedelta_2[0]
```
This might solve the error with older pandas (and if not, I think it is fine
to skip the test for those older versions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]