Skip to content

Commit 1896199

Browse files
committed
Added tests
1 parent 58284dd commit 1896199

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/arrays/categorical/test_astype.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
CategoricalDtype,
88
CategoricalIndex,
99
DatetimeIndex,
10+
Index,
1011
Interval,
1112
NaT,
1213
Period,
1314
Timestamp,
1415
array,
16+
isna,
1517
to_datetime,
1618
)
1719
import pandas._testing as tm
20+
from pandas.core.arrays.arrow.array import ArrowExtensionArray
1821

1922

2023
class TestAstype:
@@ -160,3 +163,18 @@ def test_astype_category_readonly_mask_values(self):
160163
result = arr.astype("category")
161164
expected = array([0, 1, 2], dtype="Int64").astype("category")
162165
tm.assert_extension_array_equal(result, expected)
166+
167+
def test_arrow_array_astype_to_categorical_dtype_temporal(self):
168+
arr = array(
169+
["2017-01-01", "2018-01-01", "2019-01-01"], dtype="date32[day][pyarrow]"
170+
)
171+
cats = Index(["2017-01-01", "2018-01-01", "2019-01-01"], dtype="M8[s]")
172+
dtype = CategoricalDtype(categories=cats, ordered=False)
173+
174+
assert not all(isna(arr.astype(dtype)))
175+
176+
arr = ArrowExtensionArray._from_sequence(["1h", "2h", "3h"])
177+
cats = Index(["1h", "2h", "3h"], dtype="m8[ns]")
178+
dtype = CategoricalDtype(cats, ordered=False)
179+
180+
assert not all(isna(arr.astype(dtype)))

0 commit comments

Comments
 (0)