diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 6aecfe5267e0c..0f1cd397f2dd1 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1753,6 +1753,13 @@ def _setitem_with_indexer(self, indexer, value, name: str = "iloc"): if not isinstance(value, ABCSeries): # if not Series (in which case we need to align), # we can short-circuit + if ( + isinstance(arr, np.ndarray) + and arr.ndim == 1 + and len(arr) == 1 + ): + # NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615 + arr = arr[0, ...] empty_value[indexer[0]] = arr self.obj[key] = empty_value return diff --git a/pandas/core/internals/base.py b/pandas/core/internals/base.py index 523dee97a3c5c..8f771221c8890 100644 --- a/pandas/core/internals/base.py +++ b/pandas/core/internals/base.py @@ -187,6 +187,10 @@ def setitem_inplace(self, indexer, value) -> None: # dt64/td64, which do their own validation. value = np_can_hold_element(arr.dtype, value) + if isinstance(value, np.ndarray) and value.ndim == 1 and len(value) == 1: + # NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615 + value = value[0, ...] + arr[indexer] = value def grouped_reduce(self, func): diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index ff022cb047f3d..94670fe47036b 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1063,7 +1063,9 @@ def setitem(self, indexer, value, using_cow: bool = False) -> Block: self = self.make_block_same_class( values.T if values.ndim == 2 else values ) - + if isinstance(casted, np.ndarray) and casted.ndim == 1 and len(casted) == 1: + # NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615 + casted = casted[0, ...] values[indexer] = casted return self diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 99fbfe46d22fc..0bac882756a91 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -1114,6 +1114,12 @@ def _make_date_converter( if date_parser is not lib.no_default and date_format is not None: raise TypeError("Cannot use both 'date_parser' and 'date_format'") + def unpack_if_single_element(arg): + # NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615 + if isinstance(arg, np.ndarray) and arg.ndim == 1 and len(arg) == 1: + return arg[0] + return arg + def converter(*date_cols, col: Hashable): if date_parser is lib.no_default: strs = parsing.concat_date_cols(date_cols) @@ -1137,7 +1143,9 @@ def converter(*date_cols, col: Hashable): else: try: result = tools.to_datetime( - date_parser(*date_cols), errors="ignore", cache=cache_dates + date_parser(*(unpack_if_single_element(arg) for arg in date_cols)), + errors="ignore", + cache=cache_dates, ) if isinstance(result, datetime.datetime): raise Exception("scalar parser") diff --git a/pandas/tests/groupby/test_groupby_dropna.py b/pandas/tests/groupby/test_groupby_dropna.py index 48cc1518937b3..551642ff64fd5 100644 --- a/pandas/tests/groupby/test_groupby_dropna.py +++ b/pandas/tests/groupby/test_groupby_dropna.py @@ -627,7 +627,7 @@ def test_categorical_transformers( result = getattr(gb_keepna, transformation_func)(*args) expected = getattr(gb_dropna, transformation_func)(*args) for iloc, value in zip( - df[df["x"].isnull()].index.tolist(), null_group_result.values + df[df["x"].isnull()].index.tolist(), null_group_result.values.ravel() ): if expected.ndim == 1: expected.iloc[iloc] = value