Skip to content

Commit f3f17cb

Browse files
[backport 2.3.x] TST (string): from_dummies, dropna (#60818) (#60856)
BUG(string): from_dummies, dropna (#60818) (cherry picked from commit ea7ff0e) Co-authored-by: jbrockmendel <[email protected]>
1 parent 8d18e04 commit f3f17cb

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
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-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import numpy as np
1212
import pytest
1313

14-
from pandas._config import using_string_dtype
15-
14+
from pandas.compat import HAS_PYARROW
1615
import pandas.util._test_decorators as td
1716

1817
import pandas as pd
@@ -2128,12 +2127,19 @@ def test_enum_column_equality():
21282127
tm.assert_series_equal(result, expected)
21292128

21302129

2131-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
2132-
def test_mixed_col_index_dtype():
2130+
def test_mixed_col_index_dtype(using_infer_string):
21332131
# GH 47382
21342132
df1 = DataFrame(columns=list("abc"), data=1.0, index=[0])
21352133
df2 = DataFrame(columns=list("abc"), data=0.0, index=[0])
21362134
df1.columns = df2.columns.astype("string")
21372135
result = df1 + df2
21382136
expected = DataFrame(columns=list("abc"), data=1.0, index=[0])
2137+
if using_infer_string:
2138+
# df2.columns.dtype will be "str" instead of object,
2139+
# so the aligned result will be "string", not object
2140+
if HAS_PYARROW:
2141+
dtype = "string[pyarrow]"
2142+
else:
2143+
dtype = "string"
2144+
expected.columns = expected.columns.astype(dtype)
21392145
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,
@@ -363,7 +361,6 @@ def test_with_prefix_contains_get_dummies_NaN_column():
363361
tm.assert_frame_equal(result, expected)
364362

365363

366-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
367364
@pytest.mark.parametrize(
368365
"default_category, expected",
369366
[
@@ -400,11 +397,13 @@ def test_with_prefix_contains_get_dummies_NaN_column():
400397
],
401398
)
402399
def test_with_prefix_default_category(
403-
dummies_with_unassigned, default_category, expected
400+
dummies_with_unassigned, default_category, expected, using_infer_string
404401
):
405402
result = from_dummies(
406403
dummies_with_unassigned, sep="_", default_category=default_category
407404
)
405+
if using_infer_string:
406+
expected = expected.astype("str")
408407
tm.assert_frame_equal(result, expected)
409408

410409

0 commit comments

Comments
 (0)