Skip to content

Commit 496c982

Browse files
authored
REF: reshape.concat operate on arrays, not SingleBlockManagers (#33125)
* REF: reshape.concat operate on arrays, not SingleBlockManagers * xfail more selectively * Revert PandasArray.astype patch
1 parent d72dc24 commit 496c982

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

pandas/core/internals/managers.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,33 +1591,6 @@ def fast_xs(self, loc):
15911591
"""
15921592
raise NotImplementedError("Use series._values[loc] instead")
15931593

1594-
def concat(
1595-
self, to_concat: List["SingleBlockManager"], new_axis: Index
1596-
) -> "SingleBlockManager":
1597-
"""
1598-
Concatenate a list of SingleBlockManagers into a single
1599-
SingleBlockManager.
1600-
1601-
Used for pd.concat of Series objects with axis=0.
1602-
1603-
Parameters
1604-
----------
1605-
to_concat : list of SingleBlockManagers
1606-
new_axis : Index of the result
1607-
1608-
Returns
1609-
-------
1610-
SingleBlockManager
1611-
"""
1612-
1613-
blocks = [obj.blocks[0] for obj in to_concat]
1614-
values = concat_compat([x.values for x in blocks])
1615-
1616-
new_block = make_block(values, placement=slice(0, len(values), 1))
1617-
1618-
mgr = SingleBlockManager(new_block, new_axis)
1619-
return mgr
1620-
16211594

16221595
# --------------------------------------------------------------------
16231596
# Constructor Helpers

pandas/core/reshape/concat.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pandas._typing import FrameOrSeriesUnion, Label
1111

12+
from pandas.core.dtypes.concat import concat_compat
1213
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
1314

1415
from pandas import DataFrame, Index, MultiIndex, Series
@@ -457,12 +458,13 @@ def get_result(self):
457458
# stack blocks
458459
if self.bm_axis == 0:
459460
name = com.consensus_name_attr(self.objs)
460-
461-
mgr = self.objs[0]._mgr.concat(
462-
[x._mgr for x in self.objs], self.new_axes[0]
463-
)
464461
cons = self.objs[0]._constructor
465-
return cons(mgr, name=name).__finalize__(self, method="concat")
462+
463+
arrs = [ser._values for ser in self.objs]
464+
465+
res = concat_compat(arrs, axis=0)
466+
result = cons(res, index=self.new_axes[0], name=name, dtype=res.dtype)
467+
return result.__finalize__(self, method="concat")
466468

467469
# combine as columns in a frame
468470
else:

pandas/tests/extension/test_numpy.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,20 @@ def test_take_series(self, data):
170170
# ValueError: PandasArray must be 1-dimensional.
171171
super().test_take_series(data)
172172

173-
@pytest.mark.xfail(reason="astype doesn't recognize data.dtype")
174173
def test_loc_iloc_frame_single_dtype(self, data):
174+
npdtype = data.dtype.numpy_dtype
175+
if npdtype == object or npdtype == np.float64:
176+
# GH#33125
177+
pytest.xfail(reason="GH#33125 astype doesn't recognize data.dtype")
175178
super().test_loc_iloc_frame_single_dtype(data)
176179

177180

178181
class TestGroupby(BaseNumPyTests, base.BaseGroupbyTests):
179182
@skip_nested
180183
def test_groupby_extension_apply(self, data_for_grouping, groupby_apply_op):
181184
# ValueError: Names should be list-like for a MultiIndex
185+
if data_for_grouping.dtype.numpy_dtype == np.float64:
186+
pytest.xfail(reason="GH#33125 astype doesn't recognize data.dtype")
182187
super().test_groupby_extension_apply(data_for_grouping, groupby_apply_op)
183188

184189

@@ -276,7 +281,11 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators):
276281

277282

278283
class TestPrinting(BaseNumPyTests, base.BasePrintingTests):
279-
pass
284+
@pytest.mark.xfail(
285+
reason="GH#33125 PandasArray.astype does not recognize PandasDtype"
286+
)
287+
def test_series_repr(self, data):
288+
super().test_series_repr(data)
280289

281290

282291
@skip_nested
@@ -321,6 +330,18 @@ class TestReshaping(BaseNumPyTests, base.BaseReshapingTests):
321330
def test_concat_mixed_dtypes(self, data):
322331
super().test_concat_mixed_dtypes(data)
323332

333+
@pytest.mark.xfail(
334+
reason="GH#33125 PandasArray.astype does not recognize PandasDtype"
335+
)
336+
def test_concat(self, data, in_frame):
337+
super().test_concat(data, in_frame)
338+
339+
@pytest.mark.xfail(
340+
reason="GH#33125 PandasArray.astype does not recognize PandasDtype"
341+
)
342+
def test_concat_all_na_block(self, data_missing, in_frame):
343+
super().test_concat_all_na_block(data_missing, in_frame)
344+
324345
@skip_nested
325346
def test_merge(self, data, na_value):
326347
# Fails creating expected

0 commit comments

Comments
 (0)