Skip to content

Tslib unused #17402

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 2 commits into from
Sep 1, 2017
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
6 changes: 1 addition & 5 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2622,8 +2622,6 @@ cdef class _Timedelta(timedelta):
int ndim

if isinstance(other, _Timedelta):
if isinstance(other, _NaT):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you think this can be removed? are the NaT comparisons handled higher up (IOW they never hit this)? (I don't remember)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See discussion in #17379. TLDR: _NaT does not subclass _Timedelta, so something very weird would have to be going on for this condition to be satisfied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In [1]: pd.Timedelta('1 day') > pd.NaT
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-9550edbbc777> in <module>()
----> 1 pd.Timedelta('1 day') > pd.NaT

/Users/jreback/pandas/pandas/_libs/tslib.pyx in pandas._libs.tslib._Timedelta.__richcmp__ (pandas/_libs/tslib.c:47402)()
   2653                 elif op == Py_NE:
   2654                     return True
-> 2655                 raise TypeError('Cannot compare type %r with type %r' %
   2656                                 (type(self).__name__, type(other).__name__))
   2657 

TypeError: Cannot compare type 'Timedelta' with type 'NaTType'

In [2]: pd.Timedelta('1 day') == pd.NaT
Out[2]: False

right so this is ok

return _cmp_nat_dt(other, self, _reverse_ops[op])
ots = other
elif isinstance(other, timedelta):
ots = Timedelta(other)
Expand Down Expand Up @@ -3882,7 +3880,7 @@ fields = ['year', 'quarter', 'month', 'day', 'hour',
'minute', 'second', 'millisecond', 'microsecond', 'nanosecond',
'week', 'dayofyear', 'weekofyear', 'days_in_month', 'daysinmonth',
'dayofweek', 'weekday_name', 'days', 'seconds', 'microseconds',
'nanoseconds', 'qyear', 'quarter']
'nanoseconds', 'qyear']
for field in fields:
prop = property(fget=lambda self: np.nan)
setattr(NaTType, field, prop)
Expand Down Expand Up @@ -4620,7 +4618,6 @@ def build_field_sarray(ndarray[int64_t] dtindex):
"""
cdef:
Py_ssize_t i, count = 0
int isleap
pandas_datetimestruct dts
ndarray[int32_t] years, months, days, hours, minutes, seconds, mus

Expand Down Expand Up @@ -5270,7 +5267,6 @@ cpdef _isleapyear_arr(ndarray years):
def monthrange(int64_t year, int64_t month):
cdef:
int64_t days
int64_t day_of_week

if month < 1 or month > 12:
raise ValueError("bad month number 0; must be 1-12")
Expand Down