Skip to content

Commit 22fa9ac

Browse files
jbrockmendelJulianWgs
authored andcommitted
CLN: remove unnecessary Categorical._validate_setitem_key (pandas-dev#37068)
1 parent f51cc99 commit 22fa9ac

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

pandas/core/arrays/categorical.py

+1-27
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pandas._config import get_option
1111

12-
from pandas._libs import NaT, algos as libalgos, hashtable as htable, lib
12+
from pandas._libs import NaT, algos as libalgos, hashtable as htable
1313
from pandas._typing import ArrayLike, Dtype, Ordered, Scalar
1414
from pandas.compat.numpy import function as nv
1515
from pandas.util._decorators import cache_readonly, deprecate_kwarg
@@ -1907,32 +1907,6 @@ def _validate_setitem_value(self, value):
19071907

19081908
return self._unbox_listlike(rvalue)
19091909

1910-
def _validate_setitem_key(self, key):
1911-
if lib.is_integer(key):
1912-
# set by position
1913-
pass
1914-
1915-
elif isinstance(key, tuple):
1916-
# tuple of indexers (dataframe)
1917-
# only allow 1 dimensional slicing, but can
1918-
# in a 2-d case be passed (slice(None),....)
1919-
if len(key) == 2:
1920-
if not com.is_null_slice(key[0]):
1921-
raise AssertionError("invalid slicing for a 1-ndim categorical")
1922-
key = key[1]
1923-
elif len(key) == 1:
1924-
key = key[0]
1925-
else:
1926-
raise AssertionError("invalid slicing for a 1-ndim categorical")
1927-
1928-
elif isinstance(key, slice):
1929-
# slicing in Series or Categorical
1930-
pass
1931-
1932-
# else: array of True/False in Series or Categorical
1933-
1934-
return super()._validate_setitem_key(key)
1935-
19361910
def _reverse_indexer(self) -> Dict[Hashable, np.ndarray]:
19371911
"""
19381912
Compute the inverse of a categorical, returning

pandas/core/internals/blocks.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -2008,25 +2008,21 @@ class NumericBlock(Block):
20082008
_can_hold_na = True
20092009

20102010

2011-
class FloatOrComplexBlock(NumericBlock):
2012-
__slots__ = ()
2013-
2014-
2015-
class FloatBlock(FloatOrComplexBlock):
2011+
class FloatBlock(NumericBlock):
20162012
__slots__ = ()
20172013
is_float = True
20182014

20192015
def _can_hold_element(self, element: Any) -> bool:
20202016
tipo = maybe_infer_dtype_type(element)
20212017
if tipo is not None:
20222018
return issubclass(tipo.type, (np.floating, np.integer)) and not issubclass(
2023-
tipo.type, (np.datetime64, np.timedelta64)
2019+
tipo.type, np.timedelta64
20242020
)
20252021
return isinstance(
20262022
element, (float, int, np.floating, np.int_)
20272023
) and not isinstance(
20282024
element,
2029-
(bool, np.bool_, datetime, timedelta, np.datetime64, np.timedelta64),
2025+
(bool, np.bool_, np.timedelta64),
20302026
)
20312027

20322028
def to_native_types(
@@ -2063,7 +2059,7 @@ def to_native_types(
20632059
return self.make_block(res)
20642060

20652061

2066-
class ComplexBlock(FloatOrComplexBlock):
2062+
class ComplexBlock(NumericBlock):
20672063
__slots__ = ()
20682064
is_complex = True
20692065

@@ -2086,7 +2082,7 @@ def _can_hold_element(self, element: Any) -> bool:
20862082
if tipo is not None:
20872083
return (
20882084
issubclass(tipo.type, np.integer)
2089-
and not issubclass(tipo.type, (np.datetime64, np.timedelta64))
2085+
and not issubclass(tipo.type, np.timedelta64)
20902086
and self.dtype.itemsize >= tipo.itemsize
20912087
)
20922088
# We have not inferred an integer from the dtype

0 commit comments

Comments
 (0)