Skip to content

Commit

Permalink
BUG(string): from_dummies, dropna (#60818)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Jan 30, 2025
1 parent c36da3f commit ea7ff0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pandas/tests/frame/methods/test_dropna.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

import pandas as pd
from pandas import (
DataFrame,
Expand Down Expand Up @@ -184,10 +182,12 @@ def test_dropna_multiple_axes(self):
with pytest.raises(TypeError, match="supplying multiple axes"):
inp.dropna(how="all", axis=(0, 1), inplace=True)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_dropna_tz_aware_datetime(self):
def test_dropna_tz_aware_datetime(self, using_infer_string):
# GH13407

df = DataFrame()
if using_infer_string:
df.columns = df.columns.astype("str")
dt1 = datetime.datetime(2015, 1, 1, tzinfo=dateutil.tz.tzutc())
dt2 = datetime.datetime(2015, 2, 2, tzinfo=dateutil.tz.tzutc())
df["Time"] = [dt1]
Expand Down
13 changes: 10 additions & 3 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype
from pandas.compat import HAS_PYARROW

import pandas as pd
from pandas import (
Expand Down Expand Up @@ -2126,12 +2126,19 @@ def test_enum_column_equality():
tm.assert_series_equal(result, expected)


@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_mixed_col_index_dtype():
def test_mixed_col_index_dtype(using_infer_string):
# GH 47382
df1 = DataFrame(columns=list("abc"), data=1.0, index=[0])
df2 = DataFrame(columns=list("abc"), data=0.0, index=[0])
df1.columns = df2.columns.astype("string")
result = df1 + df2
expected = DataFrame(columns=list("abc"), data=1.0, index=[0])
if using_infer_string:
# df2.columns.dtype will be "str" instead of object,
# so the aligned result will be "string", not object
if HAS_PYARROW:
dtype = "string[pyarrow]"
else:
dtype = "string"
expected.columns = expected.columns.astype(dtype)
tm.assert_frame_equal(result, expected)
7 changes: 3 additions & 4 deletions pandas/tests/reshape/test_from_dummies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

from pandas import (
DataFrame,
Series,
Expand Down Expand Up @@ -364,7 +362,6 @@ def test_with_prefix_contains_get_dummies_NaN_column():
tm.assert_frame_equal(result, expected)


@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.parametrize(
"default_category, expected",
[
Expand Down Expand Up @@ -401,12 +398,14 @@ def test_with_prefix_contains_get_dummies_NaN_column():
],
)
def test_with_prefix_default_category(
dummies_with_unassigned, default_category, expected
dummies_with_unassigned, default_category, expected, using_infer_string
):
result = from_dummies(
dummies_with_unassigned, sep="_", default_category=default_category
)
expected = DataFrame(expected)
if using_infer_string:
expected = expected.astype("str")
tm.assert_frame_equal(result, expected)


Expand Down

0 comments on commit ea7ff0e

Please sign in to comment.