File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -2211,7 +2211,15 @@ def factorize(
2211
2211
codes = codes [::- 1 ]
2212
2212
uniques = uniques [::- 1 ]
2213
2213
return codes , uniques
2214
- # FIXME: shouldn't get here; we are ignoring sort
2214
+
2215
+ if sort :
2216
+ # algorithms.factorize only passes sort=True here when freq is
2217
+ # not None, so this should not be reached.
2218
+ raise NotImplementedError (
2219
+ f"The 'sort' keyword in { type (self ).__name__ } .factorize is "
2220
+ "ignored unless arr.freq is not None. To factorize with sort, "
2221
+ "call pd.factorize(obj, sort=True) instead."
2222
+ )
2215
2223
return super ().factorize (use_na_sentinel = use_na_sentinel )
2216
2224
2217
2225
@classmethod
Original file line number Diff line number Diff line change @@ -745,3 +745,16 @@ def test_iter_zoneinfo_fold(self, tz):
745
745
right2 = dta .astype (object )[2 ]
746
746
assert str (left ) == str (right2 )
747
747
assert left .utcoffset () == right2 .utcoffset ()
748
+
749
+
750
+ def test_factorize_sort_without_freq ():
751
+ dta = DatetimeArray ._from_sequence ([0 , 2 , 1 ])
752
+
753
+ msg = r"call pd.factorize\(obj, sort=True\) instead"
754
+ with pytest .raises (NotImplementedError , match = msg ):
755
+ dta .factorize (sort = True )
756
+
757
+ # Do TimedeltaArray while we're here
758
+ tda = dta - dta [0 ]
759
+ with pytest .raises (NotImplementedError , match = msg ):
760
+ tda .factorize (sort = True )
You can’t perform that action at this time.
0 commit comments