Skip to content

Commit b049bf3

Browse files
Revert "BUG: inconsistent concat casting EA vs non-EA (pandas-dev#38843)"
This reverts commit 2362df9.
1 parent 4dcc7d9 commit b049bf3

File tree

5 files changed

+10
-26
lines changed

5 files changed

+10
-26
lines changed

doc/source/whatsnew/v1.3.0.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,10 @@ Reshaping
312312
- Bug in :func:`merge` raising error when performing an inner join with partial index and ``right_index`` when no overlap between indices (:issue:`33814`)
313313
- Bug in :meth:`DataFrame.unstack` with missing levels led to incorrect index names (:issue:`37510`)
314314
- Bug in :func:`join` over :class:`MultiIndex` returned wrong result, when one of both indexes had only one level (:issue:`36909`)
315-
- Bug in :func:`concat` incorrectly casting to ``object`` dtype in some cases when one or more of the operands is empty (:issue:`38843`, :issue:`38907`)
316315
- :meth:`merge_asof` raises ``ValueError`` instead of cryptic ``TypeError`` in case of non-numerical merge columns (:issue:`29130`)
317-
- Bug in :func:`concat` incorrectly casting to ``object`` dtype in some cases when one or more of the operands is empty (:issue:`38843`)
316+
- Bug in :meth:`DataFrame.unstack` with missing levels led to incorrect index names (:issue:`37510`)
318317
-
319318

320-
321319
Sparse
322320
^^^^^^
323321

pandas/core/dtypes/concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def is_nonempty(x) -> bool:
127127
# marginal given that it would still require shape & dtype calculation and
128128
# np.concatenate which has them both implemented is compiled.
129129
non_empties = [x for x in to_concat if is_nonempty(x)]
130-
if non_empties:
130+
if non_empties and axis == 0:
131131
to_concat = non_empties
132132

133133
typs = _get_dtype_kinds(to_concat)

pandas/tests/indexing/test_partial.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,11 @@ def test_partial_setting_mixed_dtype(self):
170170
with pytest.raises(ValueError, match=msg):
171171
df.loc[0] = [1, 2, 3]
172172

173-
@pytest.mark.parametrize("dtype", [None, "int64", "Int64"])
174-
def test_loc_setitem_expanding_empty(self, dtype):
173+
# TODO: #15657, these are left as object and not coerced
175174
df = DataFrame(columns=["A", "B"])
175+
df.loc[3] = [6, 7]
176176

177-
value = [6, 7]
178-
if dtype == "int64":
179-
value = np.array(value, dtype=dtype)
180-
elif dtype == "Int64":
181-
value = pd.array(value, dtype=dtype)
182-
183-
df.loc[3] = value
184-
185-
exp = DataFrame([[6, 7]], index=[3], columns=["A", "B"], dtype=dtype)
186-
if dtype is not None:
187-
exp = exp.astype(dtype)
177+
exp = DataFrame([[6, 7]], index=[3], columns=["A", "B"], dtype="object")
188178
tm.assert_frame_equal(df, exp)
189179

190180
def test_series_partial_set(self):

pandas/tests/reshape/concat/test_concat.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,11 @@ def test_concat_will_upcast(dt, pdt):
474474
assert x.values.dtype == "float64"
475475

476476

477-
@pytest.mark.parametrize("dtype", ["int64", "Int64"])
478-
def test_concat_empty_and_non_empty_frame_regression(dtype):
477+
def test_concat_empty_and_non_empty_frame_regression():
479478
# GH 18178 regression test
480-
df1 = DataFrame({"foo": [1]}).astype(dtype)
479+
df1 = DataFrame({"foo": [1]})
481480
df2 = DataFrame({"foo": []})
482-
expected = df1
481+
expected = DataFrame({"foo": [1.0]})
483482
result = pd.concat([df1, df2])
484483
tm.assert_frame_equal(result, expected)
485484

pandas/tests/reshape/concat/test_empty.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,12 @@ def test_concat_empty_series_dtypes_sparse(self):
202202
expected = pd.SparseDtype("object")
203203
assert result.dtype == expected
204204

205-
@pytest.mark.parametrize("dtype", ["int64", "Int64"])
206-
def test_concat_empty_df_object_dtype(self, dtype):
205+
def test_concat_empty_df_object_dtype(self):
207206
# GH 9149
208207
df_1 = DataFrame({"Row": [0, 1, 1], "EmptyCol": np.nan, "NumberCol": [1, 2, 3]})
209-
df_1["Row"] = df_1["Row"].astype(dtype)
210208
df_2 = DataFrame(columns=df_1.columns)
211209
result = pd.concat([df_1, df_2], axis=0)
212-
expected = df_1.copy()
213-
expected["EmptyCol"] = expected["EmptyCol"].astype(object) # TODO: why?
210+
expected = df_1.astype(object)
214211
tm.assert_frame_equal(result, expected)
215212

216213
def test_concat_empty_dataframe_dtypes(self):

0 commit comments

Comments
 (0)