7
7
import numpy as np
8
8
import pytest
9
9
10
- from pandas ._libs .tslibs import NaT , iNaT
10
+ from pandas ._libs .tslibs import NaT
11
11
from pandas .compat import is_platform_windows
12
12
13
13
from pandas .core .dtypes .cast import maybe_promote
19
19
is_integer_dtype ,
20
20
is_object_dtype ,
21
21
is_scalar ,
22
- is_string_dtype ,
23
22
is_timedelta64_dtype ,
24
23
)
25
24
from pandas .core .dtypes .dtypes import DatetimeTZDtype
@@ -156,7 +155,7 @@ def _assert_match(result_fill_value, expected_fill_value):
156
155
match_value = result_fill_value == expected_fill_value
157
156
158
157
# Note: type check above ensures that we have the _same_ NA value
159
- # for missing values, None == None and iNaT == iNaT (which is checked
158
+ # for missing values, None == None (which is checked
160
159
# through match_value above), but np.nan != np.nan and pd.NaT != pd.NaT
161
160
match_missing = isna (result_fill_value ) and isna (expected_fill_value )
162
161
@@ -536,22 +535,15 @@ def test_maybe_promote_datetimetz_with_datetimetz(
536
535
)
537
536
538
537
539
- @pytest .mark .parametrize ("fill_value" , [None , np .nan , NaT , iNaT ])
538
+ @pytest .mark .parametrize ("fill_value" , [None , np .nan , NaT ])
540
539
# override parametrization due to to many xfails; see GH 23982 / 25425
541
540
@pytest .mark .parametrize ("box" , [(False , None )])
542
541
def test_maybe_promote_datetimetz_with_na (tz_aware_fixture , fill_value , box ):
543
542
544
543
dtype = DatetimeTZDtype (tz = tz_aware_fixture )
545
544
boxed , box_dtype = box # read from parametrized fixture
546
545
547
- # takes the opinion that DatetimeTZ should have single na-marker
548
- # using iNaT would lead to errors elsewhere -> NaT
549
- if not boxed and fill_value == iNaT :
550
- # TODO: are we sure iNaT _should_ be cast to NaT?
551
- pytest .xfail ("wrong missing value marker" )
552
-
553
546
expected_dtype = dtype
554
- # DatetimeTZDtype does not use iNaT as missing value marker
555
547
exp_val_for_scalar = NaT
556
548
exp_val_for_array = NaT
557
549
@@ -820,7 +812,7 @@ def test_maybe_promote_any_with_object(any_numpy_dtype_reduced, object_dtype, bo
820
812
)
821
813
822
814
823
- @pytest .mark .parametrize ("fill_value" , [None , np .nan , NaT , iNaT ])
815
+ @pytest .mark .parametrize ("fill_value" , [None , np .nan , NaT ])
824
816
# override parametrization due to to many xfails; see GH 23982 / 25425
825
817
@pytest .mark .parametrize ("box" , [(False , None )])
826
818
def test_maybe_promote_any_numpy_dtype_with_na (
@@ -836,37 +828,17 @@ def test_maybe_promote_any_numpy_dtype_with_na(
836
828
and fill_value is not NaT
837
829
):
838
830
pytest .xfail ("does not upcast to object" )
839
- elif dtype == "uint64" and not boxed and fill_value == iNaT :
840
- pytest .xfail ("does not upcast correctly" )
841
- # below: opinionated that iNaT should be interpreted as missing value
842
- elif (
843
- not boxed
844
- and (is_float_dtype (dtype ) or is_complex_dtype (dtype ))
845
- and fill_value == iNaT
846
- ):
847
- pytest .xfail ("does not cast to missing value marker correctly" )
848
- elif (is_string_dtype (dtype ) or dtype == bool ) and not boxed and fill_value == iNaT :
849
- pytest .xfail ("does not cast to missing value marker correctly" )
850
-
851
- if is_integer_dtype (dtype ) and dtype == "uint64" and fill_value == iNaT :
852
- # uint64 + negative int casts to object; iNaT is considered as missing
853
- expected_dtype = np .dtype (object )
854
- exp_val_for_scalar = np .nan
855
- elif is_integer_dtype (dtype ) and fill_value == iNaT :
856
- # other integer + iNaT casts to int64
857
- expected_dtype = np .int64
858
- exp_val_for_scalar = iNaT
859
831
elif is_integer_dtype (dtype ) and fill_value is not NaT :
860
832
# integer + other missing value (np.nan / None) casts to float
861
833
expected_dtype = np .float64
862
834
exp_val_for_scalar = np .nan
863
- elif is_object_dtype (dtype ) and ( fill_value == iNaT or fill_value is NaT ) :
835
+ elif is_object_dtype (dtype ) and fill_value is NaT :
864
836
# inserting into object does not cast the value
865
837
# but *does* cast None to np.nan
866
838
expected_dtype = np .dtype (object )
867
839
exp_val_for_scalar = fill_value
868
840
elif is_datetime_or_timedelta_dtype (dtype ):
869
- # datetime / timedelta cast all missing values to iNaT
841
+ # datetime / timedelta cast all missing values to dtyped-NaT
870
842
expected_dtype = dtype
871
843
exp_val_for_scalar = dtype .type ("NaT" , "ns" )
872
844
elif fill_value is NaT :
0 commit comments