Skip to content

Commit ea7ff0e

Browse files
authored
BUG(string): from_dummies, dropna (#60818)
1 parent c36da3f commit ea7ff0e

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

pandas/tests/frame/methods/test_dropna.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
from pandas._config import using_string_dtype
8-
97
import pandas as pd
108
from pandas import (
119
DataFrame,
@@ -184,10 +182,12 @@ def test_dropna_multiple_axes(self):
184182
with pytest.raises(TypeError, match="supplying multiple axes"):
185183
inp.dropna(how="all", axis=(0, 1), inplace=True)
186184

187-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
188-
def test_dropna_tz_aware_datetime(self):
185+
def test_dropna_tz_aware_datetime(self, using_infer_string):
189186
# GH13407
187+
190188
df = DataFrame()
189+
if using_infer_string:
190+
df.columns = df.columns.astype("str")
191191
dt1 = datetime.datetime(2015, 1, 1, tzinfo=dateutil.tz.tzutc())
192192
dt2 = datetime.datetime(2015, 2, 2, tzinfo=dateutil.tz.tzutc())
193193
df["Time"] = [dt1]

pandas/tests/frame/test_arithmetic.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import numpy as np
1212
import pytest
1313

14-
from pandas._config import using_string_dtype
14+
from pandas.compat import HAS_PYARROW
1515

1616
import pandas as pd
1717
from pandas import (
@@ -2126,12 +2126,19 @@ def test_enum_column_equality():
21262126
tm.assert_series_equal(result, expected)
21272127

21282128

2129-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
2130-
def test_mixed_col_index_dtype():
2129+
def test_mixed_col_index_dtype(using_infer_string):
21312130
# GH 47382
21322131
df1 = DataFrame(columns=list("abc"), data=1.0, index=[0])
21332132
df2 = DataFrame(columns=list("abc"), data=0.0, index=[0])
21342133
df1.columns = df2.columns.astype("string")
21352134
result = df1 + df2
21362135
expected = DataFrame(columns=list("abc"), data=1.0, index=[0])
2136+
if using_infer_string:
2137+
# df2.columns.dtype will be "str" instead of object,
2138+
# so the aligned result will be "string", not object
2139+
if HAS_PYARROW:
2140+
dtype = "string[pyarrow]"
2141+
else:
2142+
dtype = "string"
2143+
expected.columns = expected.columns.astype(dtype)
21372144
tm.assert_frame_equal(result, expected)

pandas/tests/reshape/test_from_dummies.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas._config import using_string_dtype
5-
64
from pandas import (
75
DataFrame,
86
Series,
@@ -364,7 +362,6 @@ def test_with_prefix_contains_get_dummies_NaN_column():
364362
tm.assert_frame_equal(result, expected)
365363

366364

367-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
368365
@pytest.mark.parametrize(
369366
"default_category, expected",
370367
[
@@ -401,12 +398,14 @@ def test_with_prefix_contains_get_dummies_NaN_column():
401398
],
402399
)
403400
def test_with_prefix_default_category(
404-
dummies_with_unassigned, default_category, expected
401+
dummies_with_unassigned, default_category, expected, using_infer_string
405402
):
406403
result = from_dummies(
407404
dummies_with_unassigned, sep="_", default_category=default_category
408405
)
409406
expected = DataFrame(expected)
407+
if using_infer_string:
408+
expected = expected.astype("str")
410409
tm.assert_frame_equal(result, expected)
411410

412411

0 commit comments

Comments
 (0)