File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ from pandas.core.dtypes.common import (
45
45
is_bool_dtype, is_object_dtype,
46
46
is_string_dtype, is_datetime64_dtype,
47
47
pandas_dtype)
48
- from pandas.core.categorical import Categorical
48
+ from pandas.core.categorical import Categorical, _recode_for_categories
49
49
from pandas.core.algorithms import take_1d
50
50
from pandas.core.dtypes.concat import union_categoricals
51
51
from pandas import Index, to_numeric, to_datetime, to_timedelta
@@ -1292,8 +1292,7 @@ cdef class TextReader:
1292
1292
dtype.categories is not None ):
1293
1293
# recode for dtype.categories
1294
1294
categories = dtype.categories
1295
- indexer = categories.get_indexer(cats)
1296
- codes = take_1d(indexer, codes, fill_value = - 1 )
1295
+ codes = _recode_for_categories(codes, cats, categories)
1297
1296
ordered = dtype.ordered
1298
1297
elif not cats.is_monotonic_increasing:
1299
1298
# sort categories and recode if necessary
Original file line number Diff line number Diff line change @@ -203,6 +203,14 @@ def test_categoricaldtype_coerces_datetime(self):
203
203
result = self .read_csv (StringIO (data ), dtype = dtype )
204
204
tm .assert_frame_equal (result , expected )
205
205
206
+ dtype = {
207
+ 'b' : CategoricalDtype ([pd .Timestamp ("2014" )])
208
+ }
209
+ data = "b\n 2014-01-01\n 2014-01-01T00:00:00"
210
+ expected = pd .DataFrame ({'b' : Categorical ([pd .Timestamp ('2014' )] * 2 )})
211
+ result = self .read_csv (StringIO (data ), dtype = dtype )
212
+ tm .assert_frame_equal (result , expected )
213
+
206
214
def test_categoricaldtype_coerces_timedelta (self ):
207
215
dtype = {'b' : CategoricalDtype (pd .to_timedelta (['1H' , '2H' , '3H' ]))}
208
216
data = "b\n 1H\n 2H\n 3H"
You can’t perform that action at this time.
0 commit comments