Skip to content

Commit

Permalink
Dont check for NaTType, just NaT (pandas-dev#17564)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and alanbato committed Nov 10, 2017
1 parent da7ad15 commit 29eb4ed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def insert(self, loc, item):
pass

freq = None
if isinstance(item, (Timedelta, libts.NaTType)):
if isinstance(item, Timedelta) or item is NaT:

# check freq can be preserved on edge cases
if self.freq is not None:
Expand Down
5 changes: 2 additions & 3 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
Index, MultiIndex, Float64Index, Int64Index,
Panel, RangeIndex, PeriodIndex, DatetimeIndex, NaT,
Categorical, CategoricalIndex)
from pandas._libs.tslib import NaTType
from pandas.core.sparse.api import SparseSeries, SparseDataFrame
from pandas.core.sparse.array import BlockIndex, IntIndex
from pandas.core.generic import NDFrame
Expand Down Expand Up @@ -470,7 +469,7 @@ def encode(obj):
}

elif isinstance(obj, (datetime, date, np.datetime64, timedelta,
np.timedelta64, NaTType)):
np.timedelta64)) or obj is NaT:
if isinstance(obj, Timestamp):
tz = obj.tzinfo
if tz is not None:
Expand All @@ -482,7 +481,7 @@ def encode(obj):
u'value': obj.value,
u'freq': freq,
u'tz': tz}
if isinstance(obj, NaTType):
if obj is NaT:
return {u'typ': u'nat'}
elif isinstance(obj, np.timedelta64):
return {u'typ': u'timedelta64',
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/scalar/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pandas.core.tools.timedeltas import _coerce_scalar_to_timedelta_type as ct
from pandas import (Timedelta, TimedeltaIndex, timedelta_range, Series,
to_timedelta, compat)
from pandas._libs.tslib import iNaT, NaTType
from pandas._libs.tslib import iNaT, NaT


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

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

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

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

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

0 comments on commit 29eb4ed

Please sign in to comment.