From 14cae3b3018867ee6c0cc56f9f94447de3a77df5 Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 11 Oct 2020 20:44:50 -0700 Subject: [PATCH] CLN: remove unnecessary Categorical._validate_setitem_key --- pandas/core/arrays/categorical.py | 28 +--------------------------- pandas/core/internals/blocks.py | 14 +++++--------- 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 8dc5e6c0ff2aa..081a363ce03c6 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -9,7 +9,7 @@ from pandas._config import get_option -from pandas._libs import NaT, algos as libalgos, hashtable as htable, lib +from pandas._libs import NaT, algos as libalgos, hashtable as htable from pandas._typing import ArrayLike, Dtype, Ordered, Scalar from pandas.compat.numpy import function as nv from pandas.util._decorators import cache_readonly, deprecate_kwarg @@ -1907,32 +1907,6 @@ def _validate_setitem_value(self, value): return self._unbox_listlike(rvalue) - def _validate_setitem_key(self, key): - if lib.is_integer(key): - # set by position - pass - - elif isinstance(key, tuple): - # tuple of indexers (dataframe) - # only allow 1 dimensional slicing, but can - # in a 2-d case be passed (slice(None),....) - if len(key) == 2: - if not com.is_null_slice(key[0]): - raise AssertionError("invalid slicing for a 1-ndim categorical") - key = key[1] - elif len(key) == 1: - key = key[0] - else: - raise AssertionError("invalid slicing for a 1-ndim categorical") - - elif isinstance(key, slice): - # slicing in Series or Categorical - pass - - # else: array of True/False in Series or Categorical - - return super()._validate_setitem_key(key) - def _reverse_indexer(self) -> Dict[Hashable, np.ndarray]: """ Compute the inverse of a categorical, returning diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index ac210ecbaad5f..67246b89a844b 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2001,11 +2001,7 @@ class NumericBlock(Block): _can_hold_na = True -class FloatOrComplexBlock(NumericBlock): - __slots__ = () - - -class FloatBlock(FloatOrComplexBlock): +class FloatBlock(NumericBlock): __slots__ = () is_float = True @@ -2013,13 +2009,13 @@ def _can_hold_element(self, element: Any) -> bool: tipo = maybe_infer_dtype_type(element) if tipo is not None: return issubclass(tipo.type, (np.floating, np.integer)) and not issubclass( - tipo.type, (np.datetime64, np.timedelta64) + tipo.type, np.timedelta64 ) return isinstance( element, (float, int, np.floating, np.int_) ) and not isinstance( element, - (bool, np.bool_, datetime, timedelta, np.datetime64, np.timedelta64), + (bool, np.bool_, np.timedelta64), ) def to_native_types( @@ -2056,7 +2052,7 @@ def to_native_types( return self.make_block(res) -class ComplexBlock(FloatOrComplexBlock): +class ComplexBlock(NumericBlock): __slots__ = () is_complex = True @@ -2079,7 +2075,7 @@ def _can_hold_element(self, element: Any) -> bool: if tipo is not None: return ( issubclass(tipo.type, np.integer) - and not issubclass(tipo.type, (np.datetime64, np.timedelta64)) + and not issubclass(tipo.type, np.timedelta64) and self.dtype.itemsize >= tipo.itemsize ) # We have not inferred an integer from the dtype