Skip to content

Commit 66eda6a

Browse files
committed
Add test of empty dataframe in ExtensionDtype
1 parent d1da8c8 commit 66eda6a

14 files changed

+80
-7
lines changed

pandas/tests/extension/arrow/test_bool.py

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ def dtype():
1515
return ArrowBoolDtype()
1616

1717

18+
@pytest.fixture
19+
def columns():
20+
values = np.random.randint(0, 2, size=100, dtype=bool)
21+
values[1] = ~values[0]
22+
return ArrowBoolArray.from_scalars(values)
23+
24+
1825
@pytest.fixture
1926
def data():
2027
values = np.random.randint(0, 2, size=100, dtype=bool)
@@ -55,6 +62,10 @@ def test_from_dtype(self, data):
5562
def test_from_sequence_from_cls(self, data):
5663
super().test_from_sequence_from_cls(data)
5764

65+
@pytest.mark.xfail(reason="bad is-na for empty data")
66+
def test_construct_empty_dataframe(self, columns, dtype):
67+
super().test_construct_empty_dataframe(columns, dtype)
68+
5869

5970
class TestReduce(base.BaseNoReduceTests):
6071
def test_reduce_series_boolean(self):

pandas/tests/extension/base/constructors.py

+4
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ def test_pandas_array_dtype(self, data):
8383
result = pd.array(data, dtype=np.dtype(object))
8484
expected = pd.arrays.PandasArray(np.asarray(data, dtype=object))
8585
self.assert_equal(result, expected)
86+
87+
def test_construct_empty_dataframe(self, columns, dtype):
88+
# GH 33623
89+
pd.DataFrame(columns=columns, dtype=dtype)

pandas/tests/extension/decimal/test_decimal.py

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def dtype():
1717
return DecimalDtype()
1818

1919

20+
@pytest.fixture
21+
def columns():
22+
return DecimalArray(make_data())
23+
24+
2025
@pytest.fixture
2126
def data():
2227
return DecimalArray(make_data())

pandas/tests/extension/json/test_json.py

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def dtype():
1515
return JSONDtype()
1616

1717

18+
@pytest.fixture
19+
def columns():
20+
data = make_data()
21+
22+
while len(data[0]) == len(data[1]):
23+
data = make_data()
24+
25+
return JSONArray(data)
26+
27+
1828
@pytest.fixture
1929
def data():
2030
"""Length-100 PeriodArray for semantics test."""

pandas/tests/extension/test_boolean.py

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def dtype():
3333
return BooleanDtype()
3434

3535

36+
@pytest.fixture
37+
def columns(dtype):
38+
return pd.array([True, False], dtype=dtype)
39+
40+
3641
@pytest.fixture
3742
def data(dtype):
3843
return pd.array(make_data(), dtype=dtype)

pandas/tests/extension/test_categorical.py

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def dtype():
4141
return CategoricalDtype()
4242

4343

44+
@pytest.fixture
45+
def columns():
46+
return Categorical(make_data())
47+
48+
4449
@pytest.fixture
4550
def data():
4651
"""Length-100 array for this type.

pandas/tests/extension/test_common.py

-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,3 @@ def test_astype_no_copy():
7979
def test_is_extension_array_dtype(dtype):
8080
assert isinstance(dtype, dtypes.ExtensionDtype)
8181
assert is_extension_array_dtype(dtype)
82-
83-
84-
@pytest.mark.parametrize("columns, dtype", [(["a"], "string")])
85-
def test_construct_empty_dataframe_with_string_dtype(columns, dtype):
86-
# GH 33623
87-
pd.DataFrame(columns=columns, dtype=dtype)

pandas/tests/extension/test_datetime.py

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ def dtype(request):
1313
return DatetimeTZDtype(unit="ns", tz=request.param)
1414

1515

16+
@pytest.fixture
17+
def columns(dtype):
18+
return DatetimeArray(pd.date_range("2000", periods=100, tz=dtype.tz), dtype=dtype)
19+
20+
1621
@pytest.fixture
1722
def data(dtype):
1823
data = DatetimeArray(pd.date_range("2000", periods=100, tz=dtype.tz), dtype=dtype)

pandas/tests/extension/test_integer.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def dtype(request):
5454
return request.param()
5555

5656

57+
@pytest.fixture
58+
def columns():
59+
return integer_array(make_data())
60+
61+
5762
@pytest.fixture
5863
def data(dtype):
5964
return integer_array(make_data(), dtype=dtype)
@@ -186,7 +191,9 @@ class TestInterface(base.BaseInterfaceTests):
186191

187192

188193
class TestConstructors(base.BaseConstructorsTests):
189-
pass
194+
@pytest.mark.xfail(reason="bad is-na for empty data")
195+
def test_construct_empty_dataframe(self, columns, dtyoe):
196+
super().test_construct_empty_dataframe(columns, dtype)
190197

191198

192199
class TestReshaping(base.BaseReshapingTests):

pandas/tests/extension/test_interval.py

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def dtype():
3535
return IntervalDtype()
3636

3737

38+
@pytest.fixture
39+
def columns():
40+
return IntervalArray(make_data())
41+
42+
3843
@pytest.fixture
3944
def data():
4045
"""Length-100 PeriodArray for semantics test."""

pandas/tests/extension/test_numpy.py

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def allow_in_pandas(monkeypatch):
3737
yield
3838

3939

40+
@pytest.fixture
41+
def columns():
42+
return PandasArray(np.arange(1, 3))
43+
44+
4045
@pytest.fixture
4146
def data(allow_in_pandas, dtype):
4247
if dtype.numpy_dtype == "object":

pandas/tests/extension/test_period.py

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def dtype():
1515
return PeriodDtype(freq="D")
1616

1717

18+
@pytest.fixture
19+
def columns(dtype):
20+
return PeriodArray(np.arange(2020, 2021), freq=dtype.freq)
21+
22+
1823
@pytest.fixture
1924
def data(dtype):
2025
return PeriodArray(np.arange(1970, 2070), freq=dtype.freq)

pandas/tests/extension/test_sparse.py

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def dtype():
2929
return SparseDtype()
3030

3131

32+
@pytest.fixture
33+
def columns():
34+
return SparseArray(np.ones(10) * 2)
35+
36+
3237
@pytest.fixture(params=[0, np.nan])
3338
def data(request):
3439
"""Length-100 PeriodArray for semantics test."""

pandas/tests/extension/test_string.py

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ def dtype():
1313
return StringDtype()
1414

1515

16+
@pytest.fixture
17+
def columns():
18+
strings = np.random.choice(list(string.ascii_letters), size=1)
19+
20+
return StringArray._from_sequence(strings)
21+
22+
1623
@pytest.fixture
1724
def data():
1825
strings = np.random.choice(list(string.ascii_letters), size=100)

0 commit comments

Comments
 (0)