Skip to content

Commit 0474c7f

Browse files
jbrockmendeljreback
authored andcommitted
TST: Fix 36 maybe_promote xfails wanting np.bytes_ instead of np.object_ (#28861)
1 parent 6241b9d commit 0474c7f

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

pandas/tests/dtypes/cast/test_promote.py

+7-25
Original file line numberDiff line numberDiff line change
@@ -485,25 +485,13 @@ def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype_reduced, box)
485485
fill_dtype = np.dtype(any_numpy_dtype_reduced)
486486
boxed, box_dtype = box # read from parametrized fixture
487487

488-
if issubclass(fill_dtype.type, np.bytes_):
489-
if not boxed or box_dtype == object:
490-
pytest.xfail("falsely upcasts to object")
491-
# takes the opinion that bool dtype has no missing value marker
492-
else:
493-
pytest.xfail("wrong missing value marker")
494-
else:
495-
if boxed and box_dtype is None:
496-
pytest.xfail("does not upcast to object")
497-
498488
# create array of given dtype; casts "1" to correct dtype
499489
fill_value = np.array([1], dtype=fill_dtype)[0]
500490

501-
# filling bytes with anything but bytes casts to object
502-
expected_dtype = (
503-
dtype if issubclass(fill_dtype.type, np.bytes_) else np.dtype(object)
504-
)
491+
# we never use bytes dtype internally, always promote to object
492+
expected_dtype = np.dtype(np.object_)
505493
exp_val_for_scalar = fill_value
506-
exp_val_for_array = None if issubclass(fill_dtype.type, np.bytes_) else np.nan
494+
exp_val_for_array = np.nan
507495

508496
_check_promote(
509497
dtype,
@@ -521,13 +509,7 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced, bytes_dtype, box)
521509
fill_dtype = np.dtype(bytes_dtype)
522510
boxed, box_dtype = box # read from parametrized fixture
523511

524-
if issubclass(dtype.type, np.bytes_):
525-
if not boxed or box_dtype == object:
526-
pytest.xfail("falsely upcasts to object")
527-
# takes the opinion that bool dtype has no missing value marker
528-
else:
529-
pytest.xfail("wrong missing value marker")
530-
else:
512+
if not issubclass(dtype.type, np.bytes_):
531513
if (
532514
boxed
533515
and (box_dtype == "bytes" or box_dtype is None)
@@ -541,11 +523,11 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced, bytes_dtype, box)
541523
# special case for box_dtype (cannot use fixture in parametrization)
542524
box_dtype = fill_dtype if box_dtype == "bytes" else box_dtype
543525

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

550532
_check_promote(
551533
dtype,

0 commit comments

Comments
 (0)