File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
pandas/tests/arrays/categorical Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 7
7
CategoricalDtype ,
8
8
CategoricalIndex ,
9
9
DatetimeIndex ,
10
+ Index ,
10
11
Interval ,
11
12
NaT ,
12
13
Period ,
13
14
Timestamp ,
14
15
array ,
16
+ isna ,
15
17
to_datetime ,
16
18
)
17
19
import pandas ._testing as tm
20
+ from pandas .core .arrays .arrow .array import ArrowExtensionArray
18
21
19
22
20
23
class TestAstype :
@@ -160,3 +163,18 @@ def test_astype_category_readonly_mask_values(self):
160
163
result = arr .astype ("category" )
161
164
expected = array ([0 , 1 , 2 ], dtype = "Int64" ).astype ("category" )
162
165
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 )))
You can’t perform that action at this time.
0 commit comments