Skip to content

Commit 8020543

Browse files
TST: Ensure dtypes are set correctly for empty integer columns #24386 (#34886)
* TST: Ensure dtypes are set correctly for empty integer columns #24386 * Add comment to refer to GH issue tracker * Refactor check, use == instead of is * Moved file to test_constructors.py and added test for other dtypes * Add support for more dtypes * Refactor testing for data types using containers in _testing.py
1 parent dab4d88 commit 8020543

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/frame/test_constructors.py

+27
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,33 @@ def test_from_records_empty_with_nonempty_fields_gh3682(self):
22452245
tm.assert_index_equal(df.index, Index([], name="id"))
22462246
assert df.index.name == "id"
22472247

2248+
@pytest.mark.parametrize(
2249+
"dtype",
2250+
tm.ALL_INT_DTYPES
2251+
+ tm.ALL_EA_INT_DTYPES
2252+
+ tm.FLOAT_DTYPES
2253+
+ tm.COMPLEX_DTYPES
2254+
+ tm.DATETIME64_DTYPES
2255+
+ tm.TIMEDELTA64_DTYPES
2256+
+ tm.BOOL_DTYPES,
2257+
)
2258+
def test_check_dtype_empty_numeric_column(self, dtype):
2259+
# GH24386: Ensure dtypes are set correctly for an empty DataFrame.
2260+
# Empty DataFrame is generated via dictionary data with non-overlapping columns.
2261+
data = pd.DataFrame({"a": [1, 2]}, columns=["b"], dtype=dtype)
2262+
2263+
assert data.b.dtype == dtype
2264+
2265+
@pytest.mark.parametrize(
2266+
"dtype", tm.STRING_DTYPES + tm.BYTES_DTYPES + tm.OBJECT_DTYPES
2267+
)
2268+
def test_check_dtype_empty_string_column(self, dtype):
2269+
# GH24386: Ensure dtypes are set correctly for an empty DataFrame.
2270+
# Empty DataFrame is generated via dictionary data with non-overlapping columns.
2271+
data = pd.DataFrame({"a": [1, 2]}, columns=["b"], dtype=dtype)
2272+
2273+
assert data.b.dtype.name == "object"
2274+
22482275
def test_from_records_with_datetimes(self):
22492276

22502277
# this may fail on certain platforms because of a numpy issue

0 commit comments

Comments
 (0)