Skip to content

TST: Remove maybe_promote tests for iNaT as an NA value #28775

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 5, 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
40 changes: 6 additions & 34 deletions pandas/tests/dtypes/cast/test_promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pytest

from pandas._libs.tslibs import NaT, iNaT
from pandas._libs.tslibs import NaT
from pandas.compat import is_platform_windows

from pandas.core.dtypes.cast import maybe_promote
Expand All @@ -19,7 +19,6 @@
is_integer_dtype,
is_object_dtype,
is_scalar,
is_string_dtype,
is_timedelta64_dtype,
)
from pandas.core.dtypes.dtypes import DatetimeTZDtype
Expand Down Expand Up @@ -156,7 +155,7 @@ def _assert_match(result_fill_value, expected_fill_value):
match_value = result_fill_value == expected_fill_value

# Note: type check above ensures that we have the _same_ NA value
# for missing values, None == None and iNaT == iNaT (which is checked
# for missing values, None == None (which is checked
# through match_value above), but np.nan != np.nan and pd.NaT != pd.NaT
match_missing = isna(result_fill_value) and isna(expected_fill_value)

Expand Down Expand Up @@ -536,22 +535,15 @@ def test_maybe_promote_datetimetz_with_datetimetz(
)


@pytest.mark.parametrize("fill_value", [None, np.nan, NaT, iNaT])
@pytest.mark.parametrize("fill_value", [None, np.nan, NaT])
# override parametrization due to to many xfails; see GH 23982 / 25425
@pytest.mark.parametrize("box", [(False, None)])
def test_maybe_promote_datetimetz_with_na(tz_aware_fixture, fill_value, box):

dtype = DatetimeTZDtype(tz=tz_aware_fixture)
boxed, box_dtype = box # read from parametrized fixture

# takes the opinion that DatetimeTZ should have single na-marker
# using iNaT would lead to errors elsewhere -> NaT
if not boxed and fill_value == iNaT:
# TODO: are we sure iNaT _should_ be cast to NaT?
pytest.xfail("wrong missing value marker")

expected_dtype = dtype
# DatetimeTZDtype does not use iNaT as missing value marker
exp_val_for_scalar = NaT
exp_val_for_array = NaT

Expand Down Expand Up @@ -820,7 +812,7 @@ def test_maybe_promote_any_with_object(any_numpy_dtype_reduced, object_dtype, bo
)


@pytest.mark.parametrize("fill_value", [None, np.nan, NaT, iNaT])
@pytest.mark.parametrize("fill_value", [None, np.nan, NaT])
# override parametrization due to to many xfails; see GH 23982 / 25425
@pytest.mark.parametrize("box", [(False, None)])
def test_maybe_promote_any_numpy_dtype_with_na(
Expand All @@ -836,37 +828,17 @@ def test_maybe_promote_any_numpy_dtype_with_na(
and fill_value is not NaT
):
pytest.xfail("does not upcast to object")
elif dtype == "uint64" and not boxed and fill_value == iNaT:
pytest.xfail("does not upcast correctly")
# below: opinionated that iNaT should be interpreted as missing value
elif (
not boxed
and (is_float_dtype(dtype) or is_complex_dtype(dtype))
and fill_value == iNaT
):
pytest.xfail("does not cast to missing value marker correctly")
elif (is_string_dtype(dtype) or dtype == bool) and not boxed and fill_value == iNaT:
pytest.xfail("does not cast to missing value marker correctly")

if is_integer_dtype(dtype) and dtype == "uint64" and fill_value == iNaT:
# uint64 + negative int casts to object; iNaT is considered as missing
expected_dtype = np.dtype(object)
exp_val_for_scalar = np.nan
elif is_integer_dtype(dtype) and fill_value == iNaT:
# other integer + iNaT casts to int64
expected_dtype = np.int64
exp_val_for_scalar = iNaT
elif is_integer_dtype(dtype) and fill_value is not NaT:
# integer + other missing value (np.nan / None) casts to float
expected_dtype = np.float64
exp_val_for_scalar = np.nan
elif is_object_dtype(dtype) and (fill_value == iNaT or fill_value is NaT):
elif is_object_dtype(dtype) and fill_value is NaT:
# inserting into object does not cast the value
# but *does* cast None to np.nan
expected_dtype = np.dtype(object)
exp_val_for_scalar = fill_value
elif is_datetime_or_timedelta_dtype(dtype):
# datetime / timedelta cast all missing values to iNaT
# datetime / timedelta cast all missing values to dtyped-NaT
expected_dtype = dtype
exp_val_for_scalar = dtype.type("NaT", "ns")
elif fill_value is NaT:
Expand Down