Skip to content

Commit 4d73daa

Browse files
ZanirPZanirP
ZanirP
authored and
ZanirP
committed
pre-commit changes #1
1 parent 5c7e193 commit 4d73daa

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

pandas/core/generic.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@
121121
pandas_dtype,
122122
)
123123
from pandas.core.dtypes.dtypes import (
124+
CategoricalDtype,
124125
DatetimeTZDtype,
125126
ExtensionDtype,
126127
PeriodDtype,
127-
CategoricalDtype
128128
)
129129
from pandas.core.dtypes.generic import (
130130
ABCDataFrame,
@@ -6455,25 +6455,27 @@ def astype(
64556455

64566456
else:
64576457
# else, only a single dtype is given
6458-
6459-
# GH 61074: Make dtype="category" imply "ordered" = False + add deprecation warning
6458+
6459+
# GH 61074: Make dtype="category" imply "ordered" = False + add deprecation warning
64606460
if dtype == "category":
64616461
if isinstance(self.dtype, CategoricalDtype):
64626462
if self.dtype.ordered:
64636463
warnings.warn(
64646464
"The 'category' dtype is being set to ordered=False by default.",
64656465
DeprecationWarning,
6466-
stacklevel=3
6467-
)
6468-
6469-
if isinstance(dtype, CategoricalDtype):
6470-
dtype = CategoricalDtype(categories=dtype.categories ,ordered=False)
6466+
stacklevel=3,
6467+
)
6468+
6469+
if isinstance(dtype, CategoricalDtype):
6470+
dtype = CategoricalDtype(
6471+
categories=dtype.categories, ordered=False
6472+
)
64716473
else:
64726474
dtype = CategoricalDtype(ordered=False)
6473-
6475+
64746476
new_data = self._mgr.astype(dtype=dtype, errors=errors)
64756477
res = self._constructor_from_mgr(new_data, axes=new_data.axes)
6476-
6478+
64776479
return res.__finalize__(self, method="astype")
64786480

64796481
# GH 33113: handle empty frame or series

pandas/tests/series/methods/test_astype.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,18 @@ def test_astype_categoricaldtype(self):
610610
def test_astype_categorical_to_categorical(
611611
self, name, dtype_ordered, series_ordered
612612
):
613-
614613
def check_deprecation_warning(series):
615-
''' Helper function to check DeprecationWarning for ordered = True conversions'''
614+
"""Helper function to check DeprecationWarning for ordered = True conversions"""
616615
msg = "The 'category' dtype is being set to ordered=False by default."
617-
with tm.assert_produces_warning(DeprecationWarning, match = msg):
616+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
618617
result = series.astype("category")
619618
assert result.dtype.ordered is False
620-
619+
621620
# GH#10696, GH#18593
622621
s_data = list("abcaacbab")
623622
s_dtype = CategoricalDtype(list("bac"), ordered=series_ordered)
624623
ser = Series(s_data, dtype=s_dtype, name=name)
625-
624+
626625
# GH#61074
627626
if series_ordered is True:
628627
check_deprecation_warning(ser)
@@ -632,7 +631,7 @@ def check_deprecation_warning(series):
632631
# GH#61074
633632
# unspecified categories
634633
dtype = CategoricalDtype(ordered=False)
635-
result = ser.astype(dtype)
634+
result = ser.astype(dtype)
636635
exp_dtype = CategoricalDtype(s_dtype.categories, ordered=False)
637636
expected = Series(s_data, name=name, dtype=exp_dtype)
638637
tm.assert_series_equal(result, expected)
@@ -641,7 +640,7 @@ def check_deprecation_warning(series):
641640
# different categories
642641
dtype = CategoricalDtype(list("adc"), False)
643642
result = ser.astype(dtype)
644-
expected = Series(s_data, name=name, dtype=dtype)
643+
expected = Series(s_data, name=name, dtype=dtype)
645644
tm.assert_series_equal(result, expected)
646645

647646
if dtype_ordered is False:

0 commit comments

Comments
 (0)