Skip to content

Commit 174e7ee

Browse files
sscheSven
authored andcommitted
Added test case to lock in behaviour (pandas-dev#48541)
* Added test case to lock in behaviour * In previous versions, concatenating to empty EA was resetting type information to np.object * Update whatsnew * Addressed code review comments * whatsnew: made "Loss of dtype" more specific and improved wording (EA -> ExtensionArray, etc) * testcase: moved test case to test_empty.py and use `tm.assert_frame_equal()` with an expected dataframe * Fixed style issue * Use concat/DataFrame as they were directly imported (instead of `pd...`) * Improved whatsnew entry as per suggestion Co-authored-by: Sven <[email protected]>
1 parent d51fae7 commit 174e7ee

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

doc/source/whatsnew/v1.6.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ Sparse
214214
ExtensionArray
215215
^^^^^^^^^^^^^^
216216
- Bug in :meth:`Series.mean` overflowing unnecessarily with nullable integers (:issue:`48378`)
217+
- Bug when concatenating an empty DataFrame with an ExtensionDtype to another DataFrame with the same ExtensionDtype, the resulting dtype turned into object (:issue:`48510`)
217218
-
218219

219220
Styler

pandas/tests/reshape/concat/test_empty.py

+8
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,11 @@ def test_concat_empty_dataframe_different_dtypes(self):
284284
result = concat([df1[:0], df2[:0]])
285285
assert result["a"].dtype == np.int64
286286
assert result["b"].dtype == np.object_
287+
288+
def test_concat_to_empty_ea(self):
289+
"""48510 `concat` to an empty EA should maintain type EA dtype."""
290+
df_empty = DataFrame({"a": pd.array([], dtype=pd.Int64Dtype())})
291+
df_new = DataFrame({"a": pd.array([1, 2, 3], dtype=pd.Int64Dtype())})
292+
expected = df_new.copy()
293+
result = concat([df_empty, df_new])
294+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)