From 244406e553ce1da25f05e4ea38e7bdb3cf14bc52 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 17 Nov 2020 14:36:50 -0800 Subject: [PATCH] CLN: NDFrame._where, comment typos --- pandas/core/generic.py | 12 +++++------- pandas/core/internals/blocks.py | 6 +++--- pandas/core/series.py | 2 +- pandas/tests/series/test_arithmetic.py | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4e6aba1961b64..73f1e7127dca4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9020,7 +9020,6 @@ def _where( cond = -cond if inplace else cond # try to align with other - try_quick = True if isinstance(other, NDFrame): # align with me @@ -9059,12 +9058,11 @@ def _where( # match True cond to other elif len(cond[icond]) == len(other): - # try to not change dtype at first (if try_quick) - if try_quick: - new_other = np.asarray(self) - new_other = new_other.copy() - new_other[icond] = other - other = new_other + # try to not change dtype at first + new_other = np.asarray(self) + new_other = new_other.copy() + new_other[icond] = other + other = new_other else: raise ValueError( diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 967e218078a28..7f071c0d7eed6 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1447,6 +1447,7 @@ def where( if values.ndim - 1 == other.ndim and axis == 1: other = other.reshape(tuple(other.shape + (1,))) elif transpose and values.ndim == self.ndim - 1: + # TODO(EA2D): not neceesssary with 2D EAs cond = cond.T if not hasattr(cond, "shape"): @@ -2413,9 +2414,8 @@ def _can_hold_element(self, element: Any) -> bool: return is_valid_nat_for_dtype(element, self.dtype) def fillna(self, value, **kwargs): - - # allow filling with integers to be - # interpreted as nanoseconds + # TODO(EA2D): if we operated on array_values, TDA.fillna would handle + # raising here. if is_integer(value): # Deprecation GH#24694, GH#19233 raise TypeError( diff --git a/pandas/core/series.py b/pandas/core/series.py index 800da18142825..42a87b003f634 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1015,7 +1015,7 @@ def __setitem__(self, key, value): # positional setter values[key] = value else: - # GH#12862 adding an new key to the Series + # GH#12862 adding a new key to the Series self.loc[key] = value except TypeError as err: diff --git a/pandas/tests/series/test_arithmetic.py b/pandas/tests/series/test_arithmetic.py index fa8f85178ba9f..6aad2cadf78ba 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -757,7 +757,7 @@ def test_align_date_objects_with_datetimeindex(self): @pytest.mark.parametrize("box", [list, tuple, np.array, pd.Index, pd.Series, pd.array]) @pytest.mark.parametrize("flex", [True, False]) def test_series_ops_name_retention(flex, box, names, all_binary_operators): - # GH#33930 consistent name renteiton + # GH#33930 consistent name retention op = all_binary_operators if op is ops.rfloordiv and box in [list, tuple]: