Skip to content

Commit f02bdb1

Browse files
add test
1 parent cf095e1 commit f02bdb1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pandas/tests/reshape/concat/test_concat.py

+34
Original file line numberDiff line numberDiff line change
@@ -755,3 +755,37 @@ def test_concat_retain_attrs(data):
755755
df2.attrs = {1: 1}
756756
df = concat([df1, df2])
757757
assert df.attrs[1] == 1
758+
759+
760+
@pytest.mark.parametrize("df_dtype", ["float64", "int64", "datetime64[ns]"])
761+
@pytest.mark.parametrize("empty_dtype", [None, "float64", "object"])
762+
def test_concat_ignore_emtpy_object_float(empty_dtype, df_dtype):
763+
# https://github.com/pandas-dev/pandas/issues/45637
764+
df = DataFrame({"foo": [1, 2], "bar": [1, 2]}, dtype=df_dtype)
765+
empty = DataFrame(columns=["foo", "bar"], dtype=empty_dtype)
766+
result = concat([empty, df])
767+
expected = df
768+
if df_dtype == "int64":
769+
# TODO what exact behaviour do we want for integer eventually?
770+
if empty_dtype == "float64":
771+
expected = df.astype("float64")
772+
else:
773+
expected = df.astype("object")
774+
tm.assert_frame_equal(result, expected)
775+
776+
777+
@pytest.mark.parametrize("df_dtype", ["float64", "int64", "datetime64[ns]"])
778+
@pytest.mark.parametrize("empty_dtype", [None, "float64", "object"])
779+
def test_concat_ignore_all_na_object_float(empty_dtype, df_dtype):
780+
df = DataFrame({"foo": [1, 2], "bar": [1, 2]}, dtype=df_dtype)
781+
empty = DataFrame({"foo": [np.nan], "bar": [np.nan]}, dtype=empty_dtype)
782+
result = concat([empty, df], ignore_index=True)
783+
784+
if df_dtype == "int64":
785+
# TODO what exact behaviour do we want for integer eventually?
786+
if empty_dtype == "object":
787+
df_dtype = "object"
788+
else:
789+
df_dtype = "float64"
790+
expected = DataFrame({"foo": [None, 1, 2], "bar": [None, 1, 2]}, dtype=df_dtype)
791+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)