Skip to content

Commit 148200f

Browse files
jbrockmendeljreback
authored andcommitted
Dont check for NaTType, just NaT (#17564)
1 parent e57f189 commit 148200f

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

pandas/core/indexes/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def insert(self, loc, item):
847847
pass
848848

849849
freq = None
850-
if isinstance(item, (Timedelta, libts.NaTType)):
850+
if isinstance(item, Timedelta) or item is NaT:
851851

852852
# check freq can be preserved on edge cases
853853
if self.freq is not None:

pandas/io/packers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
Index, MultiIndex, Float64Index, Int64Index,
5757
Panel, RangeIndex, PeriodIndex, DatetimeIndex, NaT,
5858
Categorical, CategoricalIndex)
59-
from pandas._libs.tslib import NaTType
6059
from pandas.core.sparse.api import SparseSeries, SparseDataFrame
6160
from pandas.core.sparse.array import BlockIndex, IntIndex
6261
from pandas.core.generic import NDFrame
@@ -470,7 +469,7 @@ def encode(obj):
470469
}
471470

472471
elif isinstance(obj, (datetime, date, np.datetime64, timedelta,
473-
np.timedelta64, NaTType)):
472+
np.timedelta64)) or obj is NaT:
474473
if isinstance(obj, Timestamp):
475474
tz = obj.tzinfo
476475
if tz is not None:
@@ -482,7 +481,7 @@ def encode(obj):
482481
u'value': obj.value,
483482
u'freq': freq,
484483
u'tz': tz}
485-
if isinstance(obj, NaTType):
484+
if obj is NaT:
486485
return {u'typ': u'nat'}
487486
elif isinstance(obj, np.timedelta64):
488487
return {u'typ': u'timedelta64',

pandas/tests/scalar/test_timedelta.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas.core.tools.timedeltas import _coerce_scalar_to_timedelta_type as ct
1010
from pandas import (Timedelta, TimedeltaIndex, timedelta_range, Series,
1111
to_timedelta, compat)
12-
from pandas._libs.tslib import iNaT, NaTType
12+
from pandas._libs.tslib import iNaT, NaT
1313

1414

1515
class TestTimedeltas(object):
@@ -579,7 +579,7 @@ def test_implementation_limits(self):
579579
assert max_td.value == np.iinfo(np.int64).max
580580

581581
# Beyond lower limit, a NAT before the Overflow
582-
assert isinstance(min_td - Timedelta(1, 'ns'), NaTType)
582+
assert (min_td - Timedelta(1, 'ns')) is NaT
583583

584584
with pytest.raises(OverflowError):
585585
min_td - Timedelta(2, 'ns')
@@ -589,7 +589,7 @@ def test_implementation_limits(self):
589589

590590
# Same tests using the internal nanosecond values
591591
td = Timedelta(min_td.value - 1, 'ns')
592-
assert isinstance(td, NaTType)
592+
assert td is NaT
593593

594594
with pytest.raises(OverflowError):
595595
Timedelta(min_td.value - 2, 'ns')

0 commit comments

Comments
 (0)