Skip to content
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

24024 follow-up: fix incorrectly accepting iNaT in validate_fill_value #24605

Merged
merged 3 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions pandas/_libs/algos_common_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ def ensure_object(object arr):
return arr
else:
return arr.astype(np.object_)
elif hasattr(arr, '_box_values_as_index'):
return arr._box_values_as_index()
else:
return np.array(arr, dtype=np.object_)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def astype(self, dtype, copy=True):

@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__)
def _validate_fill_value(self, fill_value):
if isna(fill_value) or fill_value == iNaT:
if isna(fill_value):
fill_value = iNaT
elif isinstance(fill_value, (datetime, np.datetime64)):
self._assert_tzawareness_compat(fill_value)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from pandas._libs import lib, tslib, tslibs
from pandas._libs.tslibs import OutOfBoundsDatetime, Period, iNaT
from pandas._libs.tslibs import NaT, OutOfBoundsDatetime, Period, iNaT
from pandas.compat import PY3, string_types, text_type, to_str

from .common import (
Expand Down Expand Up @@ -272,7 +272,7 @@ def maybe_promote(dtype, fill_value=np.nan):
fill_value = tslibs.Timedelta(fill_value).value
elif is_datetime64tz_dtype(dtype):
if isna(fill_value):
fill_value = iNaT
fill_value = NaT
elif is_extension_array_dtype(dtype) and isna(fill_value):
fill_value = dtype.na_value
elif is_float(fill_value):
Expand Down
9 changes: 0 additions & 9 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,6 @@ def _ensure_localized(self, arg, ambiguous='raise', nonexistent='raise',
return type(self)._simple_new(result, name=self.name)
return arg

def _box_values_as_index(self):
"""
Return object Index which contains boxed values.
"""
# XXX: this is broken (not called) for PeriodIndex, which doesn't
# define _box_values AFAICT
from pandas.core.index import Index
return Index(self._box_values(self.asi8), name=self.name, dtype=object)

def _box_values(self, values):
return self._data._box_values(values)

Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ def test_take_fill_valid(self, datetime_index, tz_naive_fixture):
# Timestamp with mismatched tz-awareness
arr.take([-1, 1], allow_fill=True, fill_value=now)

with pytest.raises(ValueError):
# require NaT, not iNaT, as it could be confused with an integer
arr.take([-1, 1], allow_fill=True, fill_value=pd.NaT.value)

def test_concat_same_type_invalid(self, datetime_index):
# different timezones
dti = datetime_index
Expand Down