Skip to content

DEPS: Address numpy deprecation of len 1 arrays assignment #52906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 26, 2023
4 changes: 4 additions & 0 deletions pandas/core/internals/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_groupby_dropna.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down