From c5e1276a52f09aeab5d3fe9703a0af54b2756a2f Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 18 Jan 2022 10:43:45 -0800 Subject: [PATCH 1/4] CI: py38 builds --- pandas/tests/extension/json/array.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/extension/json/array.py b/pandas/tests/extension/json/array.py index 538ca83667ef5..af40bb2b1d45a 100644 --- a/pandas/tests/extension/json/array.py +++ b/pandas/tests/extension/json/array.py @@ -145,6 +145,9 @@ def __ne__(self, other): def __array__(self, dtype=None): if dtype is None: dtype = object + if dtype == object: + # on py38 builds it looks like numpy is inferring to a non-1D array + return construct_1d_object_array_from_listlike(self) return np.asarray(self.data, dtype=dtype) @property From a59debccc5100d98e4f88db6734f10111114a596 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 18 Jan 2022 12:03:23 -0800 Subject: [PATCH 2/4] troubleshoot --- pandas/tests/extension/json/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/extension/json/array.py b/pandas/tests/extension/json/array.py index af40bb2b1d45a..2ce242baf2e5e 100644 --- a/pandas/tests/extension/json/array.py +++ b/pandas/tests/extension/json/array.py @@ -147,7 +147,7 @@ def __array__(self, dtype=None): dtype = object if dtype == object: # on py38 builds it looks like numpy is inferring to a non-1D array - return construct_1d_object_array_from_listlike(self) + return construct_1d_object_array_from_listlike(list(self)) return np.asarray(self.data, dtype=dtype) @property From 14f8172ded687d3d17d4d0f8dd49e3e3093db09f Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 17 Jan 2022 20:23:05 -0800 Subject: [PATCH 3/4] REF: remove Block.putmask fallback to where --- pandas/core/internals/blocks.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index ef1cd92a60540..afeaf665e1972 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -30,7 +30,6 @@ Shape, npt, ) -from pandas.compat import np_version_under1p20 from pandas.util._decorators import cache_readonly from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_bool_kwarg @@ -39,7 +38,6 @@ from pandas.core.dtypes.cast import ( can_hold_element, find_result_type, - infer_dtype_from, maybe_downcast_numeric, maybe_downcast_to_dtype, soft_convert_objects, @@ -988,12 +986,6 @@ def putmask(self, mask, new) -> list[Block]: putmask_without_repeat(values.T, mask, new) return [self] - elif np_version_under1p20 and infer_dtype_from(new)[0].kind in ["m", "M"]: - # using putmask with object dtype will incorrectly cast to object - # Having excluded self._can_hold_element, we know we cannot operate - # in-place, so we are safe using `where` - return self.where(new, ~mask) - elif noop: return [self] From aba56c6e3bd6380afc832db3e916c9f4a23fd1e7 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 18 Jan 2022 12:11:58 -0800 Subject: [PATCH 4/4] py38 compat --- pandas/core/array_algos/putmask.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index 24a0f83dbb313..daf7d0bd3f213 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -126,6 +126,8 @@ def putmask_without_repeat( mask : np.ndarray[bool] new : Any """ + new = setitem_datetimelike_compat(values, mask.sum(), new) + if getattr(new, "ndim", 0) >= 1: new = new.astype(values.dtype, copy=False)