Skip to content

Commit 7cf832c

Browse files
committed
must go faster
1 parent 3f67301 commit 7cf832c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

pandas/core/arrays/masked.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1651,19 +1651,28 @@ def transpose_homogeneous_masked_arrays(
16511651
same dtype. The caller is responsible for ensuring validity of input data.
16521652
"""
16531653
masked_arrays = list(masked_arrays)
1654+
dtype = masked_arrays[0].dtype
1655+
16541656
values = [arr._data.reshape(1, -1) for arr in masked_arrays]
1655-
transposed_values = np.concatenate(values, axis=0)
1657+
transposed_values = np.concatenate(
1658+
values,
1659+
axis=0,
1660+
out=np.empty(
1661+
(len(masked_arrays), len(masked_arrays[0])),
1662+
order="F",
1663+
dtype=dtype.numpy_dtype,
1664+
),
1665+
)
16561666

16571667
masks = [arr._mask.reshape(1, -1) for arr in masked_arrays]
1658-
transposed_masks = np.concatenate(masks, axis=0)
1668+
transposed_masks = np.concatenate(
1669+
masks, axis=0, out=np.empty_like(transposed_values, dtype=bool)
1670+
)
16591671

1660-
dtype = masked_arrays[0].dtype
16611672
arr_type = dtype.construct_array_type()
16621673
transposed_arrays: list[BaseMaskedArray] = []
16631674
for i in range(transposed_values.shape[1]):
1664-
transposed_arr = arr_type(
1665-
transposed_values[:, i].copy(), mask=transposed_masks[:, i].copy()
1666-
)
1675+
transposed_arr = arr_type(transposed_values[:, i], mask=transposed_masks[:, i])
16671676
transposed_arrays.append(transposed_arr)
16681677

16691678
return transposed_arrays

pandas/tests/frame/methods/test_transpose.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_transpose_not_inferring_dt_mixed_blocks(self):
184184
@pytest.mark.parametrize("dtype1", ["Int64", "Float64"])
185185
@pytest.mark.parametrize("dtype2", ["Int64", "Float64"])
186186
def test_transpose(self, dtype1, dtype2):
187-
# GH#57315 - transpose should have C/F contiguous blocks
187+
# GH#57315 - transpose should have F contiguous blocks
188188
df = DataFrame(
189189
{
190190
"a": pd.array([1, 1, 2], dtype=dtype1),

0 commit comments

Comments
 (0)