Skip to content

disallow np.timedelta64 in is_integer #27401

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 1 commit into from
Jul 15, 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
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ cdef inline bint is_integer_object(object obj) nogil:
-----
This counts np.timedelta64 objects as integers.
"""
return not PyBool_Check(obj) and PyArray_IsIntegerScalar(obj)
return (not PyBool_Check(obj) and PyArray_IsIntegerScalar(obj)
and not is_timedelta64_object(obj))


cdef inline bint is_float_object(object obj) nogil:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def _maybe_cast_slice_bound(self, label, side, kind):
return lbound
else:
return lbound + to_offset(parsed.resolution_string) - Timedelta(1, "ns")
elif (is_integer(label) or is_float(label)) and not is_timedelta64_dtype(label):
elif is_integer(label) or is_float(label):
self._invalid_indexer("slice", label)

return label
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2609,15 +2609,13 @@ def _can_hold_element(self, element):
return issubclass(tipo.type, (np.timedelta64, np.int64))
elif element is NaT:
return True
return is_integer(element) or isinstance(
element, (timedelta, np.timedelta64, np.int64)
)
return is_integer(element) or isinstance(element, (timedelta, np.timedelta64))

def fillna(self, value, **kwargs):

# allow filling with integers to be
# interpreted as nanoseconds
if is_integer(value) and not isinstance(value, np.timedelta64):
if is_integer(value):
# Deprecation GH#24694, GH#19233
warnings.warn(
"Passing integers to fillna is deprecated, will "
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,9 +1203,7 @@ def test_is_integer(self):
assert not is_integer(Timestamp("2011-01-01", tz="US/Eastern"))
assert not is_integer(timedelta(1000))
assert not is_integer(Timedelta("1 days"))

# questionable
assert is_integer(np.timedelta64(1, "D"))
assert not is_integer(np.timedelta64(1, "D"))

def test_is_float(self):
assert is_float(1.1)
Expand Down