From 1c8930052ae80a6d9165fe83e56b9646bbbd4904 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 8 Oct 2019 15:43:32 -0700 Subject: [PATCH 1/3] TST: Fix expecting np.bytes_ instead of np.object_ --- pandas/tests/dtypes/cast/test_promote.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/dtypes/cast/test_promote.py b/pandas/tests/dtypes/cast/test_promote.py index e4e5a22ea6ca0..77b8b0b29ea01 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -543,7 +543,7 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced, bytes_dtype, box) boxed, box_dtype = box # read from parametrized fixture if issubclass(dtype.type, np.bytes_): - if not boxed or box_dtype == object: + if box_dtype == object: pytest.xfail("falsely upcasts to object") # takes the opinion that bool dtype has no missing value marker else: @@ -562,8 +562,8 @@ 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 From 4c859c163fd006421e19ec84c8d8ff142732db83 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 8 Oct 2019 15:48:32 -0700 Subject: [PATCH 2/3] TST: fix xfailing tests with np.bytes_ --- pandas/tests/dtypes/cast/test_promote.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pandas/tests/dtypes/cast/test_promote.py b/pandas/tests/dtypes/cast/test_promote.py index 77b8b0b29ea01..55dd2a4677f18 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -542,13 +542,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 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_): if ( boxed and (box_dtype == "bytes" or box_dtype is None) @@ -566,7 +560,7 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced, bytes_dtype, box) 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, From 43b329c86a830688c6f0fedac1284369855a4812 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 8 Oct 2019 15:52:42 -0700 Subject: [PATCH 3/3] TST: Fix xfailed tests with np.bytes_ --- pandas/tests/dtypes/cast/test_promote.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/pandas/tests/dtypes/cast/test_promote.py b/pandas/tests/dtypes/cast/test_promote.py index 55dd2a4677f18..b498d589119d2 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -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,