Skip to content

Commit 4dcc7d9

Browse files
Revert "BUG: casting on concat with empties (pandas-dev#38907)"
This reverts commit 04282c7.
1 parent 6e707f2 commit 4dcc7d9

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

doc/source/whatsnew/v1.3.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ Reshaping
314314
- Bug in :func:`join` over :class:`MultiIndex` returned wrong result, when one of both indexes had only one level (:issue:`36909`)
315315
- 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`)
316316
- :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`)
318+
-
319+
317320

318321
Sparse
319322
^^^^^^

pandas/core/internals/concat.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,6 @@ def _concatenate_join_units(
318318
# Concatenating join units along ax0 is handled in _merge_blocks.
319319
raise AssertionError("Concatenating join units along axis0")
320320

321-
nonempties = [
322-
x for x in join_units if x.block is None or x.block.shape[concat_axis] > 0
323-
]
324-
if nonempties:
325-
join_units = nonempties
326-
327321
empty_dtype, upcasted_na = _get_empty_dtype_and_na(join_units)
328322

329323
to_concat = [

pandas/tests/indexing/test_partial.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ def test_partial_setting_mixed_dtype(self):
154154
# columns will align
155155
df = DataFrame(columns=["A", "B"])
156156
df.loc[0] = Series(1, index=range(4))
157-
expected = DataFrame(columns=["A", "B"], index=[0], dtype=int)
158-
tm.assert_frame_equal(df, expected)
157+
tm.assert_frame_equal(df, DataFrame(columns=["A", "B"], index=[0]))
159158

160159
# columns will align
161160
df = DataFrame(columns=["A", "B"])

pandas/tests/reshape/concat/test_append.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def test_append_length0_frame(self, sort):
8282
df5 = df.append(df3, sort=sort)
8383

8484
expected = DataFrame(index=[0, 1], columns=["A", "B", "C"])
85-
expected["C"] = expected["C"].astype(np.float64)
8685
tm.assert_frame_equal(df5, expected)
8786

8887
def test_append_records(self):
@@ -341,11 +340,16 @@ def test_append_empty_frame_to_series_with_dateutil_tz(self):
341340
expected = DataFrame(
342341
[[np.nan, np.nan, 1.0, 2.0, date]], columns=["c", "d", "a", "b", "date"]
343342
)
343+
# These columns get cast to object after append
344+
expected["c"] = expected["c"].astype(object)
345+
expected["d"] = expected["d"].astype(object)
344346
tm.assert_frame_equal(result_a, expected)
345347

346348
expected = DataFrame(
347349
[[np.nan, np.nan, 1.0, 2.0, date]] * 2, columns=["c", "d", "a", "b", "date"]
348350
)
351+
expected["c"] = expected["c"].astype(object)
352+
expected["d"] = expected["d"].astype(object)
349353

350354
result_b = result_a.append(s, ignore_index=True)
351355
tm.assert_frame_equal(result_b, expected)

pandas/tests/reshape/concat/test_empty.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def test_concat_empty_df_object_dtype(self, dtype):
210210
df_2 = DataFrame(columns=df_1.columns)
211211
result = pd.concat([df_1, df_2], axis=0)
212212
expected = df_1.copy()
213+
expected["EmptyCol"] = expected["EmptyCol"].astype(object) # TODO: why?
213214
tm.assert_frame_equal(result, expected)
214215

215216
def test_concat_empty_dataframe_dtypes(self):

0 commit comments

Comments
 (0)