From 60339ffa8a79893c199a203621221c4650daaddb Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 10 Jun 2024 10:52:35 -0700 Subject: [PATCH 1/3] Use reshape instead of flatten --- pandas/core/arrays/arrow/array.py | 2 +- pandas/core/generic.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 3d55513ab914c..d073cf0b11c6b 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -2970,7 +2970,7 @@ def transpose_homogeneous_pyarrow( """ arrays = list(arrays) nrows, ncols = len(arrays[0]), len(arrays) - indices = np.arange(nrows * ncols).reshape(ncols, nrows).T.flatten() + indices = np.arange(nrows * ncols).reshape(ncols, nrows).T.reshape(-1) arr = pa.chunked_array([chunk for arr in arrays for chunk in arr._pa_array.chunks]) arr = arr.take(indices) return [ArrowExtensionArray(arr.slice(i * ncols, ncols)) for i in range(nrows)] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 84745b25b5eef..599b3d5578fca 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9271,7 +9271,9 @@ def compare( # reorder axis to keep things organized indices = ( - np.arange(diff.shape[axis]).reshape([2, diff.shape[axis] // 2]).T.flatten() + np.arange(diff.shape[axis]) + .reshape([2, diff.shape[axis] // 2]) + .T.reshape(-1) ) diff = diff.take(indices, axis=axis) From 17511d133dc325d5bff0432785559817a618011e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:03:29 -0700 Subject: [PATCH 2/3] Use reshape instead of ravel' --- pandas/core/indexing.py | 4 ++-- pandas/core/reshape/reshape.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 9140b1dbe9b33..43fc6e0b12ef9 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2352,7 +2352,7 @@ def _align_series( def ravel(i): return i.ravel() if isinstance(i, np.ndarray) else i - indexer = tuple(map(ravel, indexer)) + indexer = map(ravel, indexer) aligners = [not com.is_null_slice(idx) for idx in indexer] sum_aligners = sum(aligners) @@ -2440,7 +2440,7 @@ def _align_frame(self, indexer, df: DataFrame) -> DataFrame: ax = self.obj.axes[i] if is_sequence(ix) or isinstance(ix, slice): if isinstance(ix, np.ndarray): - ix = ix.ravel() + ix = ix.reshape(-1) if idx is None: idx = ax[ix] elif cols is None: diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index 5426c72a356d6..a8efae8da82c8 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -842,7 +842,7 @@ def _convert_level_number(level_num: int, columns: Index): [x._values.astype(dtype, copy=False) for _, x in subset.items()] ) N, K = subset.shape - idx = np.arange(N * K).reshape(K, N).T.ravel() + idx = np.arange(N * K).reshape(K, N).T.reshape(-1) value_slice = value_slice.take(idx) else: value_slice = subset.values @@ -924,7 +924,7 @@ def _reorder_for_extension_array_stack( # idx is an indexer like # [c0r0, c1r0, c2r0, ..., # c0r1, c1r1, c2r1, ...] - idx = np.arange(n_rows * n_columns).reshape(n_columns, n_rows).T.ravel() + idx = np.arange(n_rows * n_columns).reshape(n_columns, n_rows).T.reshape(-1) return arr.take(idx) From bf889875a6934668759615acf66228708b8dc99c Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:22:11 -0700 Subject: [PATCH 3/3] add back tuple --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 43fc6e0b12ef9..8d1239ff71174 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2352,7 +2352,7 @@ def _align_series( def ravel(i): return i.ravel() if isinstance(i, np.ndarray) else i - indexer = map(ravel, indexer) + indexer = tuple(map(ravel, indexer)) aligners = [not com.is_null_slice(idx) for idx in indexer] sum_aligners = sum(aligners)