-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST (string dtype): clean-up assorted xfails #60354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
888d5cb
181c7e5
2cad97c
fc39d86
4aa160e
13a40ff
ce7cdb1
2e1d33c
eafca1c
f44f64c
053a44a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
import numpy as np | ||
import pytest | ||
|
||
from pandas._config import using_string_dtype | ||
|
||
from pandas.compat.numpy import np_version_gte1p25 | ||
|
||
import pandas as pd | ||
|
@@ -2664,46 +2662,46 @@ def test_pivot_columns_not_given(self): | |
with pytest.raises(TypeError, match="missing 1 required keyword-only argument"): | ||
df.pivot() | ||
|
||
@pytest.mark.xfail( | ||
using_string_dtype(), reason="TODO(infer_string) None is cast to NaN" | ||
) | ||
def test_pivot_columns_is_none(self): | ||
# GH#48293 | ||
df = DataFrame({None: [1], "b": 2, "c": 3}) | ||
df = DataFrame([[1, 2, 3]], columns=Index([None, "b", "c"], dtype="object")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we do need to figure out how this should work with the new string data type; the larger discussion to that is being had in #60329 (comment) |
||
result = df.pivot(columns=None) | ||
expected = DataFrame({("b", 1): [2], ("c", 1): 3}) | ||
expected.columns = expected.columns.set_levels( | ||
expected.columns.levels[0].astype(object), level=0 | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.pivot(columns=None, index="b") | ||
expected = DataFrame({("c", 1): 3}, index=Index([2], name="b")) | ||
expected.columns = expected.columns.set_levels( | ||
expected.columns.levels[0].astype(object), level=0 | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.pivot(columns=None, index="b", values="c") | ||
expected = DataFrame({1: 3}, index=Index([2], name="b")) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.xfail( | ||
using_string_dtype(), reason="TODO(infer_string) None is cast to NaN" | ||
) | ||
def test_pivot_index_is_none(self): | ||
# GH#48293 | ||
df = DataFrame({None: [1], "b": 2, "c": 3}) | ||
df = DataFrame([[1, 2, 3]], columns=Index([None, "b", "c"], dtype="object")) | ||
|
||
result = df.pivot(columns="b", index=None) | ||
expected = DataFrame({("c", 2): 3}, index=[1]) | ||
expected.columns = expected.columns.set_levels( | ||
expected.columns.levels[0].astype(object), level=0 | ||
) | ||
expected.columns.names = [None, "b"] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.pivot(columns="b", index=None, values="c") | ||
expected = DataFrame(3, index=[1], columns=Index([2], name="b")) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.xfail( | ||
using_string_dtype(), reason="TODO(infer_string) None is cast to NaN" | ||
) | ||
def test_pivot_values_is_none(self): | ||
# GH#48293 | ||
df = DataFrame({None: [1], "b": 2, "c": 3}) | ||
df = DataFrame([[1, 2, 3]], columns=Index([None, "b", "c"], dtype="object")) | ||
|
||
result = df.pivot(columns="b", index="c", values=None) | ||
expected = DataFrame( | ||
|
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 | ||
|
||
import pandas.util._test_decorators as td | ||
|
||
from pandas import ( | ||
|
@@ -98,30 +96,77 @@ def test_get_dummies_with_pyarrow_dtype(any_string_dtype, dtype): | |
|
||
|
||
# GH#47872 | ||
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") | ||
def test_get_dummies_with_str_dtype(any_string_dtype): | ||
@pytest.mark.parametrize("use_string_repr", [True, False]) | ||
def test_get_dummies_with_any_string_dtype( | ||
request, any_string_dtype, any_string_dtype2, use_string_repr, using_infer_string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a new feature for 3.0.0 (that doesn't appear to be fully tested and consistent - hence additional parameterisation addded). so using using_infer_string is probably not needed as we won't need backwards compatibility once inference is enable by default for 3.0.0 also any changes won't need backporting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I commented about this on the PR adding this test, see #59577 (comment), because I don't think it makes much sense to allow this. I see there is a PR following up on it to disallow (but so conclusion: I would leave this alone for this PR, and focus on fixing it in #59786) |
||
): | ||
s = Series(["a|b", "a|c", np.nan], dtype=any_string_dtype) | ||
result = s.str.get_dummies("|", dtype=str) | ||
expected = DataFrame( | ||
[["T", "T", "F"], ["T", "F", "T"], ["F", "F", "F"]], | ||
columns=list("abc"), | ||
dtype=str, | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
# GH#47872 | ||
@td.skip_if_no("pyarrow") | ||
def test_get_dummies_with_pa_str_dtype(any_string_dtype): | ||
s = Series(["a|b", "a|c", np.nan], dtype=any_string_dtype) | ||
result = s.str.get_dummies("|", dtype="str[pyarrow]") | ||
expected = DataFrame( | ||
[ | ||
["true", "true", "false"], | ||
["true", "false", "true"], | ||
["false", "false", "false"], | ||
], | ||
columns=list("abc"), | ||
dtype="str[pyarrow]", | ||
) | ||
test_ids = request.node.callspec.id.split("-") | ||
series_dtype_id = test_ids[0][7:] | ||
expected_dtype_id = test_ids[1][7:] | ||
if expected_dtype_id == "object": | ||
if "pyarrow" in series_dtype_id: | ||
request.applymarker( | ||
pytest.mark.xfail( | ||
reason=("pyarrow.lib.ArrowTypeError: Expected integer, got bool"), | ||
strict=True, | ||
) | ||
) | ||
expected = DataFrame( | ||
[ | ||
[True, True, False], | ||
[True, False, True], | ||
[False, False, False], | ||
], | ||
columns=list("abc"), | ||
dtype=np.bool_, | ||
) | ||
elif expected_dtype_id == "str[pyarrow]" and use_string_repr: | ||
# data type 'str[pyarrow]' uses pandas.ArrowDtype instead | ||
expected = DataFrame( | ||
[ | ||
["true", "true", "false"], | ||
["true", "false", "true"], | ||
["false", "false", "false"], | ||
], | ||
columns=list("abc"), | ||
dtype="str[pyarrow]", | ||
) | ||
elif expected_dtype_id == "str[python]" and use_string_repr: | ||
# data type 'str[python]' not understood" | ||
expected_dtype_id = str | ||
if using_infer_string: | ||
expected = DataFrame( | ||
[ | ||
["True", "True", "False"], | ||
["True", "False", "True"], | ||
["False", "False", "False"], | ||
], | ||
columns=list("abc"), | ||
dtype=expected_dtype_id, | ||
) | ||
else: | ||
expected = DataFrame( | ||
[ | ||
["T", "T", "F"], | ||
["T", "F", "T"], | ||
["F", "F", "F"], | ||
], | ||
columns=list("abc"), | ||
dtype=expected_dtype_id, | ||
) | ||
else: | ||
expected = DataFrame( | ||
[ | ||
["True", "True", "False"], | ||
["True", "False", "True"], | ||
["False", "False", "False"], | ||
], | ||
columns=list("abc"), | ||
dtype=any_string_dtype2, | ||
) | ||
if use_string_repr: | ||
result = s.str.get_dummies("|", dtype=expected_dtype_id) | ||
else: | ||
result = s.str.get_dummies("|", dtype=any_string_dtype2) | ||
tm.assert_frame_equal(result, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this commit has code changes but have pushed to this PR while we discuss