From 451d768d54a6456df87e583f8625c3297ea09a8b Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 17 Mar 2021 17:51:03 -0700 Subject: [PATCH 1/4] CLN/PERF: remove unused out keyword in algos.take_nd --- pandas/core/array_algos/take.py | 48 ++++------ pandas/core/groupby/groupby.py | 4 +- pandas/core/groupby/ops.py | 7 +- pandas/core/indexes/base.py | 10 +- pandas/core/indexes/multi.py | 8 +- pandas/core/internals/managers.py | 2 +- pandas/core/sorting.py | 5 +- pandas/tests/test_take.py | 150 ------------------------------ 8 files changed, 29 insertions(+), 205 deletions(-) diff --git a/pandas/core/array_algos/take.py b/pandas/core/array_algos/take.py index c1abd8bbf39d0..691e6085bf6bd 100644 --- a/pandas/core/array_algos/take.py +++ b/pandas/core/array_algos/take.py @@ -3,7 +3,6 @@ import functools from typing import ( TYPE_CHECKING, - Optional, overload, ) @@ -33,7 +32,6 @@ def take_nd( arr: np.ndarray, indexer, axis: int = ..., - out: Optional[np.ndarray] = ..., fill_value=..., allow_fill: bool = ..., ) -> np.ndarray: @@ -45,7 +43,6 @@ def take_nd( arr: ExtensionArray, indexer, axis: int = ..., - out: Optional[np.ndarray] = ..., fill_value=..., allow_fill: bool = ..., ) -> ArrayLike: @@ -56,7 +53,6 @@ def take_nd( arr: ArrayLike, indexer, axis: int = 0, - out: Optional[np.ndarray] = None, fill_value=lib.no_default, allow_fill: bool = True, ) -> ArrayLike: @@ -79,10 +75,6 @@ def take_nd( indices are filed with fill_value axis : int, default 0 Axis to take from - out : ndarray or None, default None - Optional output array, must be appropriate type to hold input and - fill_value together, if indexer has any -1 value entries; call - maybe_promote to determine this type for any fill_value fill_value : any, default np.nan Fill value to replace -1 values with allow_fill : boolean, default True @@ -104,14 +96,13 @@ def take_nd( return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill) arr = np.asarray(arr) - return _take_nd_ndarray(arr, indexer, axis, out, fill_value, allow_fill) + return _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill) def _take_nd_ndarray( arr: np.ndarray, indexer, axis: int, - out: Optional[np.ndarray], fill_value, allow_fill: bool, ) -> np.ndarray: @@ -122,7 +113,7 @@ def _take_nd_ndarray( else: indexer = ensure_int64(indexer, copy=False) indexer, dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value( - arr, indexer, out, fill_value, allow_fill + arr, indexer, fill_value, allow_fill ) flip_order = False @@ -132,23 +123,20 @@ def _take_nd_ndarray( if flip_order: arr = arr.T axis = arr.ndim - axis - 1 - if out is not None: - out = out.T # at this point, it's guaranteed that dtype can hold both the arr values # and the fill_value - if out is None: - out_shape_ = list(arr.shape) - out_shape_[axis] = len(indexer) - out_shape = tuple(out_shape_) - if arr.flags.f_contiguous and axis == arr.ndim - 1: - # minor tweak that can make an order-of-magnitude difference - # for dataframes initialized directly from 2-d ndarrays - # (s.t. df.values is c-contiguous and df._mgr.blocks[0] is its - # f-contiguous transpose) - out = np.empty(out_shape, dtype=dtype, order="F") - else: - out = np.empty(out_shape, dtype=dtype) + out_shape_ = list(arr.shape) + out_shape_[axis] = len(indexer) + out_shape = tuple(out_shape_) + if arr.flags.f_contiguous and axis == arr.ndim - 1: + # minor tweak that can make an order-of-magnitude difference + # for dataframes initialized directly from 2-d ndarrays + # (s.t. df.values is c-contiguous and df._mgr.blocks[0] is its + # f-contiguous transpose) + out = np.empty(out_shape, dtype=dtype, order="F") + else: + out = np.empty(out_shape, dtype=dtype) func = _get_take_nd_function( arr.ndim, arr.dtype, out.dtype, axis=axis, mask_info=mask_info @@ -193,7 +181,7 @@ def take_1d( return arr.take(indexer) indexer, dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value( - arr, indexer, None, fill_value, allow_fill + arr, indexer, fill_value, allow_fill ) # at this point, it's guaranteed that dtype can hold both the arr values @@ -517,7 +505,6 @@ def _take_2d_multi_object( def _take_preprocess_indexer_and_fill_value( arr: np.ndarray, indexer: np.ndarray, - out: Optional[np.ndarray], fill_value, allow_fill: bool, ): @@ -530,15 +517,12 @@ def _take_preprocess_indexer_and_fill_value( # check for promotion based on types only (do this first because # it's faster than computing a mask) dtype, fill_value = maybe_promote(arr.dtype, fill_value) - if dtype != arr.dtype and (out is None or out.dtype != dtype): + if dtype != arr.dtype: # check if promotion is actually required based on indexer mask = indexer == -1 needs_masking = mask.any() mask_info = mask, needs_masking - if needs_masking: - if out is not None and out.dtype != dtype: - raise TypeError("Incompatible type for fill_value") - else: + if not needs_masking: # if not, then depromote, set fill_value to dummy # (it won't be used but we don't want the cython code # to crash when trying to cast it to dtype) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 979c7aa990184..1f79823746a87 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1155,7 +1155,7 @@ def _transform_with_numba(self, data, func, *args, engine_kwargs=None, **kwargs) group_keys = self.grouper._get_group_keys() labels, _, n_groups = self.grouper.group_info sorted_index = get_group_index_sorter(labels, n_groups) - sorted_labels = algorithms.take_nd(labels, sorted_index, allow_fill=False) + sorted_labels = labels.take(sorted_index) sorted_data = data.take(sorted_index, axis=self.axis).to_numpy() starts, ends = lib.generate_slices(sorted_labels, n_groups) @@ -1190,7 +1190,7 @@ def _aggregate_with_numba(self, data, func, *args, engine_kwargs=None, **kwargs) group_keys = self.grouper._get_group_keys() labels, _, n_groups = self.grouper.group_info sorted_index = get_group_index_sorter(labels, n_groups) - sorted_labels = algorithms.take_nd(labels, sorted_index, allow_fill=False) + sorted_labels = labels.take(sorted_index) sorted_data = data.take(sorted_index, axis=self.axis).to_numpy() starts, ends = lib.generate_slices(sorted_labels, n_groups) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 74e96015b4544..5baa979bff232 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -71,7 +71,6 @@ maybe_fill, ) -import pandas.core.algorithms as algorithms from pandas.core.base import SelectionMixin import pandas.core.common as com from pandas.core.frame import DataFrame @@ -756,7 +755,7 @@ def _aggregate_series_fast(self, obj: Series, func: F): # avoids object / Series creation overhead indexer = get_group_index_sorter(group_index, ngroups) obj = obj.take(indexer) - group_index = algorithms.take_nd(group_index, indexer, allow_fill=False) + group_index = group_index.take(indexer) grouper = libreduction.SeriesGrouper(obj, func, group_index, ngroups) result, counts = grouper.get_result() return result, counts @@ -989,9 +988,9 @@ def __init__(self, data: FrameOrSeries, labels, ngroups: int, axis: int = 0): assert isinstance(axis, int), axis @cache_readonly - def slabels(self): + def slabels(self) -> np.ndarray: # Sorted labels - return algorithms.take_nd(self.labels, self.sort_idx, allow_fill=False) + return self.labels.take(self.sort_idx) @cache_readonly def sort_idx(self): diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 3a468758ab3fd..532540d92247d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2979,7 +2979,7 @@ def _union(self, other: Index, sort): missing = algos.unique1d(self.get_indexer_non_unique(other)[1]) if len(missing) > 0: - other_diff = algos.take_nd(rvals, missing, allow_fill=False) + other_diff = rvals.take(missing) result = concat_compat((lvals, other_diff)) else: # error: Incompatible types in assignment (expression has type @@ -4192,9 +4192,7 @@ def _get_leaf_sorter(labels): left_lev_indexer = ensure_int64(left_lev_indexer) rev_indexer = lib.get_reverse_indexer(left_lev_indexer, len(old_level)) old_codes = left.codes[level] - new_lev_codes = algos.take_nd( - rev_indexer, old_codes[old_codes != -1], allow_fill=False - ) + new_lev_codes = rev_indexer.take(old_codes[old_codes != -1]) new_codes = list(left.codes) new_codes[level] = new_lev_codes @@ -4242,9 +4240,7 @@ def _get_leaf_sorter(labels): ) if right_lev_indexer is not None: - right_indexer = algos.take_nd( - right_lev_indexer, join_index.codes[level], allow_fill=False - ) + right_indexer = right_lev_indexer.take(join_index.codes[level]) else: right_indexer = join_index.codes[level] diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 97492f35232e3..19fbd59f1a599 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -3541,14 +3541,10 @@ def equals(self, other: object) -> bool: if not np.array_equal(self_mask, other_mask): return False self_codes = self_codes[~self_mask] - self_values = algos.take_nd( - np.asarray(self.levels[i]._values), self_codes, allow_fill=False - ) + self_values = self.levels[i]._values.take(self_codes) other_codes = other_codes[~other_mask] - other_values = algos.take_nd( - np.asarray(other.levels[i]._values), other_codes, allow_fill=False - ) + other_values = other.levels[i]._values.take(other_codes) # since we use NaT both datetime64 and timedelta64 we can have a # situation where a level is typed say timedelta64 in self (IOW it diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index ea264da4c7b5f..8dc0eea8f9ae5 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -307,7 +307,7 @@ def items(self) -> Index: def get_dtypes(self): dtypes = np.array([blk.dtype for blk in self.blocks]) - return algos.take_nd(dtypes, self.blknos, allow_fill=False) + return dtypes.take(self.blknos) @property def arrays(self) -> List[ArrayLike]: diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index 720643d3d98aa..29e2912e110a6 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -33,7 +33,6 @@ from pandas.core.dtypes.generic import ABCMultiIndex from pandas.core.dtypes.missing import isna -import pandas.core.algorithms as algorithms from pandas.core.construction import extract_array if TYPE_CHECKING: @@ -632,10 +631,10 @@ def _reorder_by_uniques(uniques, labels): mask = labels < 0 # move labels to right locations (ie, unsort ascending labels) - labels = algorithms.take_nd(reverse_indexer, labels, allow_fill=False) + labels = reverse_indexer.take(labels) np.putmask(labels, mask, -1) # sort observed ids - uniques = algorithms.take_nd(uniques, sorter, allow_fill=False) + uniques = uniques.take(sorter) return uniques, labels diff --git a/pandas/tests/test_take.py b/pandas/tests/test_take.py index 1c7c02ea41f2c..4a2e3f971670e 100644 --- a/pandas/tests/test_take.py +++ b/pandas/tests/test_take.py @@ -72,34 +72,6 @@ class TestTake: # Standard incompatible fill error. fill_error = re.compile("Incompatible type for fill_value") - def test_1d_with_out(self, dtype_can_hold_na, writeable): - dtype, can_hold_na = dtype_can_hold_na - - data = np.random.randint(0, 2, 4).astype(dtype) - data.flags.writeable = writeable - - indexer = [2, 1, 0, 1] - out = np.empty(4, dtype=dtype) - algos.take_nd(data, indexer, out=out) - - expected = data.take(indexer) - tm.assert_almost_equal(out, expected) - - indexer = [2, 1, 0, -1] - out = np.empty(4, dtype=dtype) - - if can_hold_na: - algos.take_nd(data, indexer, out=out) - expected = data.take(indexer) - expected[3] = np.nan - tm.assert_almost_equal(out, expected) - else: - with pytest.raises(TypeError, match=self.fill_error): - algos.take_nd(data, indexer, out=out) - - # No Exception otherwise. - data.take(indexer, out=out) - def test_1d_fill_nonna(self, dtype_fill_out_dtype): dtype, fill_value, out_dtype = dtype_fill_out_dtype data = np.random.randint(0, 2, 4).astype(dtype) @@ -116,46 +88,6 @@ def test_1d_fill_nonna(self, dtype_fill_out_dtype): assert (result[[0, 1, 2, 3]] == data[indexer]).all() assert result.dtype == dtype - def test_2d_with_out(self, dtype_can_hold_na, writeable): - dtype, can_hold_na = dtype_can_hold_na - - data = np.random.randint(0, 2, (5, 3)).astype(dtype) - data.flags.writeable = writeable - - indexer = [2, 1, 0, 1] - out0 = np.empty((4, 3), dtype=dtype) - out1 = np.empty((5, 4), dtype=dtype) - algos.take_nd(data, indexer, out=out0, axis=0) - algos.take_nd(data, indexer, out=out1, axis=1) - - expected0 = data.take(indexer, axis=0) - expected1 = data.take(indexer, axis=1) - tm.assert_almost_equal(out0, expected0) - tm.assert_almost_equal(out1, expected1) - - indexer = [2, 1, 0, -1] - out0 = np.empty((4, 3), dtype=dtype) - out1 = np.empty((5, 4), dtype=dtype) - - if can_hold_na: - algos.take_nd(data, indexer, out=out0, axis=0) - algos.take_nd(data, indexer, out=out1, axis=1) - - expected0 = data.take(indexer, axis=0) - expected1 = data.take(indexer, axis=1) - expected0[3, :] = np.nan - expected1[:, 3] = np.nan - - tm.assert_almost_equal(out0, expected0) - tm.assert_almost_equal(out1, expected1) - else: - for i, out in enumerate([out0, out1]): - with pytest.raises(TypeError, match=self.fill_error): - algos.take_nd(data, indexer, out=out, axis=i) - - # No Exception otherwise. - data.take(indexer, out=out, axis=i) - def test_2d_fill_nonna(self, dtype_fill_out_dtype): dtype, fill_value, out_dtype = dtype_fill_out_dtype data = np.random.randint(0, 2, (5, 3)).astype(dtype) @@ -180,57 +112,6 @@ def test_2d_fill_nonna(self, dtype_fill_out_dtype): assert (result[:, [0, 1, 2, 3]] == data[:, indexer]).all() assert result.dtype == dtype - def test_3d_with_out(self, dtype_can_hold_na): - dtype, can_hold_na = dtype_can_hold_na - - data = np.random.randint(0, 2, (5, 4, 3)).astype(dtype) - indexer = [2, 1, 0, 1] - - out0 = np.empty((4, 4, 3), dtype=dtype) - out1 = np.empty((5, 4, 3), dtype=dtype) - out2 = np.empty((5, 4, 4), dtype=dtype) - - algos.take_nd(data, indexer, out=out0, axis=0) - algos.take_nd(data, indexer, out=out1, axis=1) - algos.take_nd(data, indexer, out=out2, axis=2) - - expected0 = data.take(indexer, axis=0) - expected1 = data.take(indexer, axis=1) - expected2 = data.take(indexer, axis=2) - - tm.assert_almost_equal(out0, expected0) - tm.assert_almost_equal(out1, expected1) - tm.assert_almost_equal(out2, expected2) - - indexer = [2, 1, 0, -1] - out0 = np.empty((4, 4, 3), dtype=dtype) - out1 = np.empty((5, 4, 3), dtype=dtype) - out2 = np.empty((5, 4, 4), dtype=dtype) - - if can_hold_na: - algos.take_nd(data, indexer, out=out0, axis=0) - algos.take_nd(data, indexer, out=out1, axis=1) - algos.take_nd(data, indexer, out=out2, axis=2) - - expected0 = data.take(indexer, axis=0) - expected1 = data.take(indexer, axis=1) - expected2 = data.take(indexer, axis=2) - - expected0[3, :, :] = np.nan - expected1[:, 3, :] = np.nan - expected2[:, :, 3] = np.nan - - tm.assert_almost_equal(out0, expected0) - tm.assert_almost_equal(out1, expected1) - tm.assert_almost_equal(out2, expected2) - else: - for i, out in enumerate([out0, out1, out2]): - with pytest.raises(TypeError, match=self.fill_error): - algos.take_nd(data, indexer, out=out, axis=i) - - # No Exception otherwise. - data.take(indexer, out=out, axis=i) - def test_3d_fill_nonna(self, dtype_fill_out_dtype): dtype, fill_value, out_dtype = dtype_fill_out_dtype @@ -321,24 +202,13 @@ def test_2d_float32(self): # axis=0 result = algos.take_nd(arr, indexer, axis=0) - result2 = np.empty_like(result) - algos.take_nd(arr, indexer, axis=0, out=result2) - tm.assert_almost_equal(result, result2) expected = arr.take(indexer, axis=0) expected[[2, 4], :] = np.nan tm.assert_almost_equal(result, expected) - # this now accepts a float32! # test with float64 out buffer - out = np.empty((len(indexer), arr.shape[1]), dtype="float32") - algos.take_nd(arr, indexer, out=out) # it works! - # axis=1 result = algos.take_nd(arr, indexer, axis=1) - result2 = np.empty_like(result) - algos.take_nd(arr, indexer, axis=1, out=result2) - tm.assert_almost_equal(result, result2) - expected = arr.take(indexer, axis=1) expected[:, [2, 4]] = np.nan tm.assert_almost_equal(result, expected) @@ -351,42 +221,22 @@ def test_2d_datetime64(self): # axis=0 result = algos.take_nd(arr, indexer, axis=0) - result2 = np.empty_like(result) - algos.take_nd(arr, indexer, axis=0, out=result2) - tm.assert_almost_equal(result, result2) - expected = arr.take(indexer, axis=0) expected.view(np.int64)[[2, 4], :] = iNaT tm.assert_almost_equal(result, expected) result = algos.take_nd(arr, indexer, axis=0, fill_value=datetime(2007, 1, 1)) - result2 = np.empty_like(result) - algos.take_nd( - arr, indexer, out=result2, axis=0, fill_value=datetime(2007, 1, 1) - ) - tm.assert_almost_equal(result, result2) - expected = arr.take(indexer, axis=0) expected[[2, 4], :] = datetime(2007, 1, 1) tm.assert_almost_equal(result, expected) # axis=1 result = algos.take_nd(arr, indexer, axis=1) - result2 = np.empty_like(result) - algos.take_nd(arr, indexer, axis=1, out=result2) - tm.assert_almost_equal(result, result2) - expected = arr.take(indexer, axis=1) expected.view(np.int64)[:, [2, 4]] = iNaT tm.assert_almost_equal(result, expected) result = algos.take_nd(arr, indexer, axis=1, fill_value=datetime(2007, 1, 1)) - result2 = np.empty_like(result) - algos.take_nd( - arr, indexer, out=result2, axis=1, fill_value=datetime(2007, 1, 1) - ) - tm.assert_almost_equal(result, result2) - expected = arr.take(indexer, axis=1) expected[:, [2, 4]] = datetime(2007, 1, 1) tm.assert_almost_equal(result, expected) From 04bc955dec412715931c67ccd96319838cacb562 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 17 Mar 2021 18:38:25 -0700 Subject: [PATCH 2/4] CLN: simplify take_nd and helpers --- pandas/core/array_algos/take.py | 47 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/pandas/core/array_algos/take.py b/pandas/core/array_algos/take.py index 691e6085bf6bd..687c32e069752 100644 --- a/pandas/core/array_algos/take.py +++ b/pandas/core/array_algos/take.py @@ -112,8 +112,12 @@ def _take_nd_ndarray( dtype, fill_value = arr.dtype, arr.dtype.type() else: indexer = ensure_int64(indexer, copy=False) - indexer, dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value( - arr, indexer, fill_value, allow_fill + + if not allow_fill: + return arr.take(indexer, axis=axis) + + dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value( + arr, indexer, fill_value ) flip_order = False @@ -180,8 +184,8 @@ def take_1d( if not allow_fill: return arr.take(indexer) - indexer, dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value( - arr, indexer, fill_value, allow_fill + dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value( + arr, indexer, fill_value ) # at this point, it's guaranteed that dtype can hold both the arr values @@ -506,26 +510,21 @@ def _take_preprocess_indexer_and_fill_value( arr: np.ndarray, indexer: np.ndarray, fill_value, - allow_fill: bool, ): mask_info = None - if not allow_fill: - dtype, fill_value = arr.dtype, arr.dtype.type() - mask_info = None, False - else: - # check for promotion based on types only (do this first because - # it's faster than computing a mask) - dtype, fill_value = maybe_promote(arr.dtype, fill_value) - if dtype != arr.dtype: - # check if promotion is actually required based on indexer - mask = indexer == -1 - needs_masking = mask.any() - mask_info = mask, needs_masking - if not needs_masking: - # if not, then depromote, set fill_value to dummy - # (it won't be used but we don't want the cython code - # to crash when trying to cast it to dtype) - dtype, fill_value = arr.dtype, arr.dtype.type() - - return indexer, dtype, fill_value, mask_info + # check for promotion based on types only (do this first because + # it's faster than computing a mask) + dtype, fill_value = maybe_promote(arr.dtype, fill_value) + if dtype != arr.dtype: + # check if promotion is actually required based on indexer + mask = indexer == -1 + needs_masking = mask.any() + mask_info = mask, needs_masking + if not needs_masking: + # if not, then depromote, set fill_value to dummy + # (it won't be used but we don't want the cython code + # to crash when trying to cast it to dtype) + dtype, fill_value = arr.dtype, arr.dtype.type() + + return dtype, fill_value, mask_info From 647a3939c89f236033c06afe120c8e879bf1f853 Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 20 Mar 2021 10:26:16 -0700 Subject: [PATCH 3/4] DOC: suppress warnings from CategoricalBlock deprecation --- doc/source/user_guide/io.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index cf153ddd2cbbd..3b7a6037a9715 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -5240,6 +5240,7 @@ Write to a feather file. Read from a feather file. .. ipython:: python + :okwarning: result = pd.read_feather("example.feather") result @@ -5323,6 +5324,7 @@ Write to a parquet file. Read from a parquet file. .. ipython:: python + :okwarning: result = pd.read_parquet("example_fp.parquet", engine="fastparquet") result = pd.read_parquet("example_pa.parquet", engine="pyarrow") From 55563284a6b4704b17bc06a4232a849fea38092b Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 20 Mar 2021 21:01:54 -0700 Subject: [PATCH 4/4] fix blknos --- pandas/core/internals/managers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 887d89e88d998..9286976713f9f 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1179,7 +1179,7 @@ def value_getitem(placement): is_deleted = np.zeros(self.nblocks, dtype=np.bool_) is_deleted[removed_blknos] = True - new_blknos = np.empty(self.nblocks, dtype=np.int64) + new_blknos = np.empty(self.nblocks, dtype=np.intp) new_blknos.fill(-1) new_blknos[~is_deleted] = np.arange(self.nblocks - len(removed_blknos)) self._blknos = new_blknos[self._blknos]