@@ -332,7 +332,7 @@ class Categorical(NDArrayBackedExtensionArray, PandasObject, ObjectStringArrayMi
332
332
333
333
>>> pd.Categorical(["a", "b", "c", "a", "b", "c"])
334
334
['a', 'b', 'c', 'a', 'b', 'c']
335
- Categories (3, object ): ['a', 'b', 'c']
335
+ Categories (3, str ): ['a', 'b', 'c']
336
336
337
337
Missing values are not included as a category.
338
338
@@ -355,7 +355,7 @@ class Categorical(NDArrayBackedExtensionArray, PandasObject, ObjectStringArrayMi
355
355
... )
356
356
>>> c
357
357
['a', 'b', 'c', 'a', 'b', 'c']
358
- Categories (3, object ): ['c' < 'b' < 'a']
358
+ Categories (3, str ): ['c' < 'b' < 'a']
359
359
>>> c.min()
360
360
'c'
361
361
"""
@@ -510,9 +510,9 @@ def dtype(self) -> CategoricalDtype:
510
510
>>> cat = pd.Categorical(["a", "b"], ordered=True)
511
511
>>> cat
512
512
['a', 'b']
513
- Categories (2, object ): ['a' < 'b']
513
+ Categories (2, str ): ['a' < 'b']
514
514
>>> cat.dtype
515
- CategoricalDtype(categories=['a', 'b'], ordered=True, categories_dtype=object )
515
+ CategoricalDtype(categories=['a', 'b'], ordered=True, categories_dtype=str )
516
516
"""
517
517
return self ._dtype
518
518
@@ -740,7 +740,7 @@ def from_codes(
740
740
>>> dtype = pd.CategoricalDtype(["a", "b"], ordered=True)
741
741
>>> pd.Categorical.from_codes(codes=[0, 1, 0, 1], dtype=dtype)
742
742
['a', 'b', 'a', 'b']
743
- Categories (2, object ): ['a' < 'b']
743
+ Categories (2, str ): ['a' < 'b']
744
744
"""
745
745
dtype = CategoricalDtype ._from_values_or_dtype (
746
746
categories = categories , ordered = ordered , dtype = dtype
@@ -922,12 +922,12 @@ def _set_categories(self, categories, fastpath: bool = False) -> None:
922
922
>>> c = pd.Categorical(["a", "b"])
923
923
>>> c
924
924
['a', 'b']
925
- Categories (2, object ): ['a', 'b']
925
+ Categories (2, str ): ['a', 'b']
926
926
927
927
>>> c._set_categories(pd.Index(["a", "c"]))
928
928
>>> c
929
929
['a', 'c']
930
- Categories (2, object ): ['a', 'c']
930
+ Categories (2, str ): ['a', 'c']
931
931
"""
932
932
if fastpath :
933
933
new_dtype = CategoricalDtype ._from_fastpath (categories , self .ordered )
@@ -1111,15 +1111,15 @@ def set_categories(
1111
1111
2 c
1112
1112
3 NaN
1113
1113
dtype: category
1114
- Categories (3, object ): ['a' < 'b' < 'c']
1114
+ Categories (3, str ): ['a' < 'b' < 'c']
1115
1115
1116
1116
>>> ser.cat.set_categories(["A", "B", "C"], rename=True)
1117
1117
0 A
1118
1118
1 B
1119
1119
2 C
1120
1120
3 NaN
1121
1121
dtype: category
1122
- Categories (3, object ): ['A' < 'B' < 'C']
1122
+ Categories (3, str ): ['A' < 'B' < 'C']
1123
1123
1124
1124
For :class:`pandas.CategoricalIndex`:
1125
1125
@@ -1215,13 +1215,13 @@ def rename_categories(self, new_categories) -> Self:
1215
1215
1216
1216
>>> c.rename_categories({"a": "A", "c": "C"})
1217
1217
['A', 'A', 'b']
1218
- Categories (2, object ): ['A', 'b']
1218
+ Categories (2, str ): ['A', 'b']
1219
1219
1220
1220
You may also provide a callable to create the new categories
1221
1221
1222
1222
>>> c.rename_categories(lambda x: x.upper())
1223
1223
['A', 'A', 'B']
1224
- Categories (2, object ): ['A', 'B']
1224
+ Categories (2, str ): ['A', 'B']
1225
1225
"""
1226
1226
1227
1227
if is_dict_like (new_categories ):
@@ -1281,15 +1281,15 @@ def reorder_categories(self, new_categories, ordered=None) -> Self:
1281
1281
2 c
1282
1282
3 a
1283
1283
dtype: category
1284
- Categories (3, object ): ['c' < 'b' < 'a']
1284
+ Categories (3, str ): ['c' < 'b' < 'a']
1285
1285
1286
1286
>>> ser.sort_values()
1287
1287
2 c
1288
1288
1 b
1289
1289
0 a
1290
1290
3 a
1291
1291
dtype: category
1292
- Categories (3, object ): ['c' < 'b' < 'a']
1292
+ Categories (3, str ): ['c' < 'b' < 'a']
1293
1293
1294
1294
For :class:`pandas.CategoricalIndex`:
1295
1295
@@ -1346,11 +1346,11 @@ def add_categories(self, new_categories) -> Self:
1346
1346
>>> c = pd.Categorical(["c", "b", "c"])
1347
1347
>>> c
1348
1348
['c', 'b', 'c']
1349
- Categories (2, object ): ['b', 'c']
1349
+ Categories (2, str ): ['b', 'c']
1350
1350
1351
1351
>>> c.add_categories(["d", "a"])
1352
1352
['c', 'b', 'c']
1353
- Categories (4, object ): ['b', 'c', 'd', 'a']
1353
+ Categories (4, str ): ['b', 'c', 'd', 'a']
1354
1354
"""
1355
1355
1356
1356
if not is_list_like (new_categories ):
@@ -1414,11 +1414,11 @@ def remove_categories(self, removals) -> Self:
1414
1414
>>> c = pd.Categorical(["a", "c", "b", "c", "d"])
1415
1415
>>> c
1416
1416
['a', 'c', 'b', 'c', 'd']
1417
- Categories (4, object ): ['a', 'b', 'c', 'd']
1417
+ Categories (4, str ): ['a', 'b', 'c', 'd']
1418
1418
1419
1419
>>> c.remove_categories(["d", "a"])
1420
1420
[NaN, 'c', 'b', 'c', NaN]
1421
- Categories (2, object ): ['b', 'c']
1421
+ Categories (2, str ): ['b', 'c']
1422
1422
"""
1423
1423
from pandas import Index
1424
1424
@@ -1465,17 +1465,17 @@ def remove_unused_categories(self) -> Self:
1465
1465
>>> c = pd.Categorical(["a", "c", "b", "c", "d"])
1466
1466
>>> c
1467
1467
['a', 'c', 'b', 'c', 'd']
1468
- Categories (4, object ): ['a', 'b', 'c', 'd']
1468
+ Categories (4, str ): ['a', 'b', 'c', 'd']
1469
1469
1470
1470
>>> c[2] = "a"
1471
1471
>>> c[4] = "c"
1472
1472
>>> c
1473
1473
['a', 'c', 'a', 'c', 'c']
1474
- Categories (4, object ): ['a', 'b', 'c', 'd']
1474
+ Categories (4, str ): ['a', 'b', 'c', 'd']
1475
1475
1476
1476
>>> c.remove_unused_categories()
1477
1477
['a', 'c', 'a', 'c', 'c']
1478
- Categories (2, object ): ['a', 'c']
1478
+ Categories (2, str ): ['a', 'c']
1479
1479
"""
1480
1480
idx , inv = np .unique (self ._codes , return_inverse = True )
1481
1481
@@ -1540,35 +1540,35 @@ def map(
1540
1540
>>> cat = pd.Categorical(["a", "b", "c"])
1541
1541
>>> cat
1542
1542
['a', 'b', 'c']
1543
- Categories (3, object ): ['a', 'b', 'c']
1543
+ Categories (3, str ): ['a', 'b', 'c']
1544
1544
>>> cat.map(lambda x: x.upper(), na_action=None)
1545
1545
['A', 'B', 'C']
1546
- Categories (3, object ): ['A', 'B', 'C']
1546
+ Categories (3, str ): ['A', 'B', 'C']
1547
1547
>>> cat.map({"a": "first", "b": "second", "c": "third"}, na_action=None)
1548
1548
['first', 'second', 'third']
1549
- Categories (3, object ): ['first', 'second', 'third']
1549
+ Categories (3, str ): ['first', 'second', 'third']
1550
1550
1551
1551
If the mapping is one-to-one the ordering of the categories is
1552
1552
preserved:
1553
1553
1554
1554
>>> cat = pd.Categorical(["a", "b", "c"], ordered=True)
1555
1555
>>> cat
1556
1556
['a', 'b', 'c']
1557
- Categories (3, object ): ['a' < 'b' < 'c']
1557
+ Categories (3, str ): ['a' < 'b' < 'c']
1558
1558
>>> cat.map({"a": 3, "b": 2, "c": 1}, na_action=None)
1559
1559
[3, 2, 1]
1560
1560
Categories (3, int64): [3 < 2 < 1]
1561
1561
1562
1562
If the mapping is not one-to-one an :class:`~pandas.Index` is returned:
1563
1563
1564
1564
>>> cat.map({"a": "first", "b": "second", "c": "first"}, na_action=None)
1565
- Index(['first', 'second', 'first'], dtype='object ')
1565
+ Index(['first', 'second', 'first'], dtype='str ')
1566
1566
1567
1567
If a `dict` is used, all unmapped categories are mapped to `NaN` and
1568
1568
the result is an :class:`~pandas.Index`:
1569
1569
1570
1570
>>> cat.map({"a": "first", "b": "second"}, na_action=None)
1571
- Index(['first', 'second', nan], dtype='object ')
1571
+ Index(['first', 'second', nan], dtype='str ')
1572
1572
"""
1573
1573
assert callable (mapper ) or is_dict_like (mapper )
1574
1574
@@ -2383,9 +2383,9 @@ def _reverse_indexer(self) -> dict[Hashable, npt.NDArray[np.intp]]:
2383
2383
>>> c = pd.Categorical(list("aabca"))
2384
2384
>>> c
2385
2385
['a', 'a', 'b', 'c', 'a']
2386
- Categories (3, object ): ['a', 'b', 'c']
2386
+ Categories (3, str ): ['a', 'b', 'c']
2387
2387
>>> c.categories
2388
- Index(['a', 'b', 'c'], dtype='object ')
2388
+ Index(['a', 'b', 'c'], dtype='str ')
2389
2389
>>> c.codes
2390
2390
array([0, 0, 1, 2, 0], dtype=int8)
2391
2391
>>> c._reverse_indexer()
@@ -2517,10 +2517,10 @@ def unique(self) -> Self:
2517
2517
--------
2518
2518
>>> pd.Categorical(list("baabc")).unique()
2519
2519
['b', 'a', 'c']
2520
- Categories (3, object ): ['a', 'b', 'c']
2520
+ Categories (3, str ): ['a', 'b', 'c']
2521
2521
>>> pd.Categorical(list("baab"), categories=list("abc"), ordered=True).unique()
2522
2522
['b', 'a']
2523
- Categories (3, object ): ['a' < 'b' < 'c']
2523
+ Categories (3, str ): ['a' < 'b' < 'c']
2524
2524
"""
2525
2525
return super ().unique ()
2526
2526
@@ -2845,10 +2845,10 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2845
2845
4 c
2846
2846
5 c
2847
2847
dtype: category
2848
- Categories (3, object ): ['a', 'b', 'c']
2848
+ Categories (3, str ): ['a', 'b', 'c']
2849
2849
2850
2850
>>> s.cat.categories
2851
- Index(['a', 'b', 'c'], dtype='object ')
2851
+ Index(['a', 'b', 'c'], dtype='str ')
2852
2852
2853
2853
>>> s.cat.rename_categories(list("cba"))
2854
2854
0 c
@@ -2858,7 +2858,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2858
2858
4 a
2859
2859
5 a
2860
2860
dtype: category
2861
- Categories (3, object ): ['c', 'b', 'a']
2861
+ Categories (3, str ): ['c', 'b', 'a']
2862
2862
2863
2863
>>> s.cat.reorder_categories(list("cba"))
2864
2864
0 a
@@ -2868,7 +2868,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2868
2868
4 c
2869
2869
5 c
2870
2870
dtype: category
2871
- Categories (3, object ): ['c', 'b', 'a']
2871
+ Categories (3, str ): ['c', 'b', 'a']
2872
2872
2873
2873
>>> s.cat.add_categories(["d", "e"])
2874
2874
0 a
@@ -2878,7 +2878,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2878
2878
4 c
2879
2879
5 c
2880
2880
dtype: category
2881
- Categories (5, object ): ['a', 'b', 'c', 'd', 'e']
2881
+ Categories (5, str ): ['a', 'b', 'c', 'd', 'e']
2882
2882
2883
2883
>>> s.cat.remove_categories(["a", "c"])
2884
2884
0 NaN
@@ -2888,7 +2888,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2888
2888
4 NaN
2889
2889
5 NaN
2890
2890
dtype: category
2891
- Categories (1, object ): ['b']
2891
+ Categories (1, str ): ['b']
2892
2892
2893
2893
>>> s1 = s.cat.add_categories(["d", "e"])
2894
2894
>>> s1.cat.remove_unused_categories()
@@ -2899,7 +2899,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2899
2899
4 c
2900
2900
5 c
2901
2901
dtype: category
2902
- Categories (3, object ): ['a', 'b', 'c']
2902
+ Categories (3, str ): ['a', 'b', 'c']
2903
2903
2904
2904
>>> s.cat.set_categories(list("abcde"))
2905
2905
0 a
@@ -2909,7 +2909,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2909
2909
4 c
2910
2910
5 c
2911
2911
dtype: category
2912
- Categories (5, object ): ['a', 'b', 'c', 'd', 'e']
2912
+ Categories (5, str ): ['a', 'b', 'c', 'd', 'e']
2913
2913
2914
2914
>>> s.cat.as_ordered()
2915
2915
0 a
@@ -2919,7 +2919,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2919
2919
4 c
2920
2920
5 c
2921
2921
dtype: category
2922
- Categories (3, object ): ['a' < 'b' < 'c']
2922
+ Categories (3, str ): ['a' < 'b' < 'c']
2923
2923
2924
2924
>>> s.cat.as_unordered()
2925
2925
0 a
@@ -2929,7 +2929,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
2929
2929
4 c
2930
2930
5 c
2931
2931
dtype: category
2932
- Categories (3, object ): ['a', 'b', 'c']
2932
+ Categories (3, str ): ['a', 'b', 'c']
2933
2933
"""
2934
2934
2935
2935
def __init__ (self , data ) -> None :
0 commit comments