File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 99from pandas ._libs .tslibs import NaT , Period , Timestamp , timezones
1010
1111from pandas .core .dtypes .generic import ABCCategoricalIndex , ABCIndexClass
12+ from .inference import is_list_like
1213
1314from pandas import compat
1415
@@ -403,7 +404,10 @@ def validate_categories(categories, fastpath=False):
403404 """
404405 from pandas import Index
405406
406- if not isinstance (categories , ABCIndexClass ):
407+ if not fastpath and not is_list_like (categories , allow_sets = True ):
408+ msg = "Parameter 'categories' must be list-like, was {!r}"
409+ raise TypeError (msg .format (categories ))
410+ elif not isinstance (categories , ABCIndexClass ):
407411 categories = Index (categories , tupleize_cols = False )
408412
409413 if not fastpath :
Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ def test_construction_from_string(self):
9494 TypeError , lambda : CategoricalDtype .construct_from_string ('foo' ))
9595
9696 def test_constructor_invalid (self ):
97- msg = "CategoricalIndex.* must be called "
97+ msg = "categories must be list-like "
9898 with pytest .raises (TypeError , match = msg ):
9999 CategoricalDtype ("category" )
100100
@@ -710,7 +710,7 @@ def test_invalid_raises(self):
710710 with pytest .raises (TypeError , match = 'ordered' ):
711711 CategoricalDtype (['a' , 'b' ], ordered = 'foo' )
712712
713- with pytest .raises (TypeError , match = 'collection ' ):
713+ with pytest .raises (TypeError , match = 'categories must be list-like ' ):
714714 CategoricalDtype ('category' )
715715
716716 def test_mixed (self ):
You can’t perform that action at this time.
0 commit comments