Skip to content

Commit 358f654

Browse files
committed
update dtype name
1 parent 6c9a33e commit 358f654

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

pandas/core/arrays/categorical.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def __init__(
453453
) from err
454454

455455
# we're inferring from values
456-
dtype = CategoricalDtype(categories, dtype.ordered, dtype.categories_dtype)
456+
dtype = CategoricalDtype(categories, dtype.ordered)
457457

458458
elif isinstance(values.dtype, CategoricalDtype):
459459
old_codes = extract_array(values)._codes
@@ -2524,7 +2524,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25242524
3 c
25252525
4 c
25262526
5 c
2527-
dtype: category
2527+
dtype: category[object]
25282528
Categories (3, object): ['a', 'b', 'c']
25292529
25302530
>>> s.cat.categories
@@ -2537,7 +2537,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25372537
3 a
25382538
4 a
25392539
5 a
2540-
dtype: category
2540+
dtype: category[object]
25412541
Categories (3, object): ['c', 'b', 'a']
25422542
25432543
>>> s.cat.reorder_categories(list("cba"))
@@ -2547,7 +2547,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25472547
3 c
25482548
4 c
25492549
5 c
2550-
dtype: category
2550+
dtype: category[object]
25512551
Categories (3, object): ['c', 'b', 'a']
25522552
25532553
>>> s.cat.add_categories(["d", "e"])
@@ -2557,7 +2557,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25572557
3 c
25582558
4 c
25592559
5 c
2560-
dtype: category
2560+
dtype: category[object]
25612561
Categories (5, object): ['a', 'b', 'c', 'd', 'e']
25622562
25632563
>>> s.cat.remove_categories(["a", "c"])
@@ -2567,7 +2567,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25672567
3 NaN
25682568
4 NaN
25692569
5 NaN
2570-
dtype: category
2570+
dtype: category[object]
25712571
Categories (1, object): ['b']
25722572
25732573
>>> s1 = s.cat.add_categories(["d", "e"])
@@ -2578,7 +2578,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25782578
3 c
25792579
4 c
25802580
5 c
2581-
dtype: category
2581+
dtype: category[object]
25822582
Categories (3, object): ['a', 'b', 'c']
25832583
25842584
>>> s.cat.set_categories(list("abcde"))
@@ -2588,7 +2588,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25882588
3 c
25892589
4 c
25902590
5 c
2591-
dtype: category
2591+
dtype: category[object]
25922592
Categories (5, object): ['a', 'b', 'c', 'd', 'e']
25932593
25942594
>>> s.cat.as_ordered()
@@ -2598,7 +2598,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25982598
3 c
25992599
4 c
26002600
5 c
2601-
dtype: category
2601+
dtype: category[object]
26022602
Categories (3, object): ['a' < 'b' < 'c']
26032603
26042604
>>> s.cat.as_unordered()
@@ -2608,7 +2608,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
26082608
3 c
26092609
4 c
26102610
5 c
2611-
dtype: category
2611+
dtype: category[object]
26122612
Categories (3, object): ['a', 'b', 'c']
26132613
"""
26142614

pandas/core/dtypes/dtypes.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
185185
186186
Examples
187187
--------
188-
>>> t = pd.CategoricalDtype(['b', 'a'], ordered=True)
188+
>>> t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True)
189189
>>> pd.Series(['a', 'b', 'a', 'c'], dtype=t)
190190
0 a
191191
1 b
192192
2 a
193193
3 NaN
194-
dtype: category
194+
dtype: category[object]
195195
Categories (2, object): ['b' < 'a']
196196
197197
An empty CategoricalDtype with a specific dtype can be created
@@ -208,7 +208,7 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
208208
base = np.dtype("O")
209209
_metadata = ("categories", "ordered")
210210
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}
211-
_categories_dtype: Dtype | None = None
211+
_categories_dtype: Dtype
212212
_match = re.compile(r"category\[(?P<categories_dtype>.+)\]")
213213

214214
def __init__(
@@ -392,13 +392,6 @@ def _get_categories_dtype_from_string(cls, string: str_type) -> str_type | None:
392392
d = match.groupdict()
393393
return d.get("categories_dtype")
394394

395-
@property
396-
def categories_dtype(self) -> Dtype:
397-
if self.categories is None:
398-
return self._categories_dtype
399-
400-
return self.categories.dtype
401-
402395
def _finalize(self, categories, ordered: Ordered, fastpath: bool = False) -> None:
403396
if ordered is not None:
404397
self.validate_ordered(ordered)
@@ -604,7 +597,7 @@ def validate_categories(self, categories, fastpath: bool = False) -> Index:
604597
raise TypeError(
605598
f"Parameter 'categories' must be list-like, was {repr(categories)}"
606599
)
607-
dtype = self._categories_dtype
600+
dtype = self.categories_dtype
608601
if not isinstance(categories, ABCIndex):
609602
categories = Index._with_infer(categories, dtype=dtype, tupleize_cols=False)
610603
elif dtype is not None:
@@ -662,6 +655,13 @@ def categories(self) -> Index:
662655
"""
663656
return self._categories
664657

658+
@property
659+
def categories_dtype(self) -> Dtype | None:
660+
try:
661+
return self.categories.dtype
662+
except AttributeError:
663+
return getattr(self, "_categories_dtype", None)
664+
665665
@property
666666
def ordered(self) -> Ordered:
667667
"""

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6343,7 +6343,7 @@ def astype(
63436343
>>> ser.astype('category')
63446344
0 1
63456345
1 2
6346-
dtype: category
6346+
dtype: category[int32]
63476347
Categories (2, int32): [1, 2]
63486348
63496349
Convert to ordered categorical type with custom ordering:
@@ -6354,7 +6354,7 @@ def astype(
63546354
>>> ser.astype(cat_dtype)
63556355
0 1
63566356
1 2
6357-
dtype: category
6357+
dtype: category[int64]
63586358
Categories (2, int64): [2 < 1]
63596359
63606360
Create a series of dates:

pandas/core/indexes/category.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ class CategoricalIndex(NDArrayBackedExtensionIndex):
147147
148148
Examples
149149
--------
150-
>>> pd.CategoricalIndex(["a", "b", "c", "a", "b", "c"])
150+
>>> pd.CategoricalIndex(["a", "b", "c", "a", "b", "c"], orderer=True)
151151
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'],
152-
categories=['a', 'b', 'c'], ordered=False, dtype='category')
152+
categories=['a', 'b', 'c'], ordered=True, dtype='category[object]')
153153
154154
``CategoricalIndex`` can also be instantiated from a ``Categorical``:
155155
156-
>>> c = pd.Categorical(["a", "b", "c", "a", "b", "c"])
156+
>>> c = pd.Categorical(["a", "b", "c", "a", "b", "c"], ordered=True)
157157
>>> pd.CategoricalIndex(c)
158158
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'],
159-
categories=['a', 'b', 'c'], ordered=False, dtype='category')
159+
categories=['a', 'b', 'c'], ordered=True, dtype='category[object]')
160160
161161
Ordered ``CategoricalIndex`` can have a min and max value.
162162
@@ -165,7 +165,7 @@ class CategoricalIndex(NDArrayBackedExtensionIndex):
165165
... )
166166
>>> ci
167167
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'],
168-
categories=['c', 'b', 'a'], ordered=True, dtype='category')
168+
categories=['c', 'b', 'a'], ordered=True, dtype='category[object]')
169169
>>> ci.min()
170170
'c'
171171
"""
@@ -438,24 +438,24 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
438438
>>> idx = pd.CategoricalIndex(['a', 'b', 'c'])
439439
>>> idx
440440
CategoricalIndex(['a', 'b', 'c'], categories=['a', 'b', 'c'],
441-
ordered=False, dtype='category')
441+
ordered=False, dtype='category[object]')
442442
>>> idx.map(lambda x: x.upper())
443443
CategoricalIndex(['A', 'B', 'C'], categories=['A', 'B', 'C'],
444-
ordered=False, dtype='category')
444+
ordered=False, dtype='category[object]')
445445
>>> idx.map({'a': 'first', 'b': 'second', 'c': 'third'})
446446
CategoricalIndex(['first', 'second', 'third'], categories=['first',
447-
'second', 'third'], ordered=False, dtype='category')
447+
'second', 'third'], ordered=False, dtype='category[object]')
448448
449449
If the mapping is one-to-one the ordering of the categories is
450450
preserved:
451451
452452
>>> idx = pd.CategoricalIndex(['a', 'b', 'c'], ordered=True)
453453
>>> idx
454454
CategoricalIndex(['a', 'b', 'c'], categories=['a', 'b', 'c'],
455-
ordered=True, dtype='category')
455+
ordered=True, dtype='category[object]')
456456
>>> idx.map({'a': 3, 'b': 2, 'c': 1})
457457
CategoricalIndex([3, 2, 1], categories=[3, 2, 1], ordered=True,
458-
dtype='category')
458+
dtype='category[int64]')
459459
460460
If the mapping is not one-to-one an :class:`~pandas.Index` is returned:
461461

pandas/core/reshape/tile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def cut(
199199
c (4.667, 7.333]
200200
d (7.333, 10.0]
201201
e (7.333, 10.0]
202-
dtype: category
202+
dtype: category[interval[float64, right]]
203203
Categories (3, interval[float64, right]): [(1.992, 4.667] < (4.667, ...
204204
205205
Passing a Series as an input returns a Series with mapping value.

0 commit comments

Comments
 (0)