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

fix interpreting int as second--> nano #24694

Merged
merged 5 commits into from
Jan 10, 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ Deprecations
- In :meth:`Series.where` with Categorical data, providing an ``other`` that is not present in the categories is deprecated. Convert the categorical to a different dtype or add the ``other`` to the categories first (:issue:`24077`).
- :meth:`Series.clip_lower`, :meth:`Series.clip_upper`, :meth:`DataFrame.clip_lower` and :meth:`DataFrame.clip_upper` are deprecated and will be removed in a future version. Use ``Series.clip(lower=threshold)``, ``Series.clip(upper=threshold)`` and the equivalent ``DataFrame`` methods (:issue:`24203`)
- :meth:`Series.nonzero` is deprecated and will be removed in a future version (:issue:`18262`)
- Passing an integer to :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtypes is deprecated, will raise ``TypeError`` in a future version. Use ``obj.fillna(pd.Timedelta(...))` instead (:issue:`24694`)

.. _whatsnew_0240.deprecations.datetimelike_int_ops:

Expand Down
8 changes: 7 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2499,8 +2499,14 @@ def _can_hold_element(self, element):
def fillna(self, value, **kwargs):

# allow filling with integers to be
# interpreted as seconds
# interpreted as nanoseconds
jreback marked this conversation as resolved.
Show resolved Hide resolved
if is_integer(value) and not isinstance(value, np.timedelta64):
# Deprecation GH#24694, GH#19233
warnings.warn("Passing integers to fillna is deprecated, will "
"raise a TypeError in a future version. To retain "
"the old behavior, pass pd.Timedelta(seconds=n) "
"instead.",
FutureWarning, stacklevel=6)
value = Timedelta(value, unit='s')
return super(TimeDeltaBlock, self).fillna(value, **kwargs)

Expand Down
17 changes: 11 additions & 6 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ def test_timedelta_fillna(self):
td = s.diff()

# reg fillna
result = td.fillna(0)
with tm.assert_produces_warning(FutureWarning):
result = td.fillna(0)
expected = Series([timedelta(0), timedelta(0), timedelta(1),
timedelta(days=1, seconds=9 * 3600 + 60 + 1)])
assert_series_equal(result, expected)

# interprested as seconds
result = td.fillna(1)
expected = Series([timedelta(seconds=1), timedelta(0), timedelta(1),
# interpreted as seconds, deprecated
with tm.assert_produces_warning(FutureWarning):
result = td.fillna(1)
expected = Series([timedelta(seconds=1),
timedelta(0), timedelta(1),
timedelta(days=1, seconds=9 * 3600 + 60 + 1)])
assert_series_equal(result, expected)

Expand All @@ -96,14 +99,16 @@ def test_timedelta_fillna(self):
# ffill
td[2] = np.nan
result = td.ffill()
expected = td.fillna(0)
with tm.assert_produces_warning(FutureWarning):
expected = td.fillna(0)
expected[0] = np.nan
assert_series_equal(result, expected)

# bfill
td[2] = np.nan
result = td.bfill()
expected = td.fillna(0)
with tm.assert_produces_warning(FutureWarning):
expected = td.fillna(0)
expected[2] = timedelta(days=1, seconds=9 * 3600 + 60 + 1)
assert_series_equal(result, expected)

Expand Down