Skip to content

TST: Fix 36 maybe_promote xfails wanting np.bytes_ instead of np.object_ #28861

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

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions pandas/tests/dtypes/cast/test_promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,25 +506,13 @@ def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype_reduced, box)
fill_dtype = np.dtype(any_numpy_dtype_reduced)
boxed, box_dtype = box # read from parametrized fixture

if issubclass(fill_dtype.type, np.bytes_):
if not boxed or box_dtype == object:
pytest.xfail("falsely upcasts to object")
# takes the opinion that bool dtype has no missing value marker
else:
pytest.xfail("wrong missing value marker")
else:
if boxed and box_dtype is None:
pytest.xfail("does not upcast to object")

# create array of given dtype; casts "1" to correct dtype
fill_value = np.array([1], dtype=fill_dtype)[0]

# filling bytes with anything but bytes casts to object
expected_dtype = (
dtype if issubclass(fill_dtype.type, np.bytes_) else np.dtype(object)
)
# we never use bytes dtype internally, always promote to object
expected_dtype = np.dtype(np.object_)
exp_val_for_scalar = fill_value
exp_val_for_array = None if issubclass(fill_dtype.type, np.bytes_) else np.nan
exp_val_for_array = np.nan

_check_promote(
dtype,
Expand All @@ -542,13 +530,7 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced, bytes_dtype, box)
fill_dtype = np.dtype(bytes_dtype)
boxed, box_dtype = box # read from parametrized fixture

if issubclass(dtype.type, np.bytes_):
if not boxed or box_dtype == object:
pytest.xfail("falsely upcasts to object")
# takes the opinion that bool dtype has no missing value marker
else:
pytest.xfail("wrong missing value marker")
else:
if not issubclass(dtype.type, np.bytes_):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could enhance / make new test that uses an object here (e.g. list / tuple), IOW something that is treated similarly but is not also a numpy dtype. (future PR)

if (
boxed
and (box_dtype == "bytes" or box_dtype is None)
Expand All @@ -562,11 +544,11 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced, bytes_dtype, box)
# special case for box_dtype (cannot use fixture in parametrization)
box_dtype = fill_dtype if box_dtype == "bytes" else box_dtype

# filling bytes with anything but bytes casts to object
expected_dtype = dtype if issubclass(dtype.type, np.bytes_) else np.dtype(object)
# we never use bytes dtype internally, always promote to object
expected_dtype = np.dtype(np.object_)
# output is not a generic bytes, but corresponds to expected_dtype
exp_val_for_scalar = np.array([fill_value], dtype=expected_dtype)[0]
exp_val_for_array = None if issubclass(dtype.type, np.bytes_) else np.nan
exp_val_for_array = np.nan

_check_promote(
dtype,
Expand Down