-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Accepts integer/float string with units and raises when unit is ambiguous (2) #23025
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
Conversation
Hello @Sup3rGeo! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 08, 2019 at 15:23 Hours UTC |
@jorisvandenbossche Ok so I created another PR, we can continue on this one |
One point we have to decide: So far, What do we want to do? In this PR I am just raising for |
The failure in TravisCI seems to be something unrelated to this feature in question. Is there anything I should change related to that? |
@jreback I really don't know what to do to make this failing test in Travis CI pass. I need some help/pointers here. |
@@ -287,7 +287,7 @@ cdef inline _decode_if_necessary(object ts): | |||
return ts | |||
|
|||
|
|||
cdef inline parse_timedelta_string(object ts): | |||
cpdef inline parse_timedelta_string(object ts, specified_unit=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
if unit is None: | ||
return 'ns' | ||
elif unit == 'M': | ||
if unit is None or unit == 'M': | ||
return unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is ok, can you add a comment
doc/source/whatsnew/v0.24.0.txt
Outdated
@@ -1132,9 +1132,9 @@ Timedelta | |||
- Fixed bug in adding a :class:`DataFrame` with all-`timedelta64[ns]` dtypes to a :class:`DataFrame` with all-integer dtypes returning incorrect results instead of raising ``TypeError`` (:issue:`22696`) | |||
- Bug in :class:`TimedeltaIndex` where adding a timezone-aware datetime scalar incorrectly returned a timezone-naive :class:`DatetimeIndex` (:issue:`23215`) | |||
- Bug in :class:`TimedeltaIndex` where adding ``np.timedelta64('NaT')`` incorrectly returned an all-`NaT` :class:`DatetimeIndex` instead of an all-`NaT` :class:`TimedeltaIndex` (:issue:`23215`) | |||
- Bug in :class:`Timedelta` where passing a string of a pure number would not take unit into account. Also raises for ambiguous/duplicate unit specification (:issue:`12136`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also mention to_timedelta
, and also the change that unit
now needs to be specified?
pandas/_libs/tslibs/timedeltas.pyx
Outdated
else: | ||
if have_value: | ||
raise ValueError("have leftover units") | ||
if len(number): | ||
r = timedelta_from_spec(number, frac, 'ns') | ||
result += timedelta_as_neg(r, neg) | ||
raise ValueError("number string without units") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I mentioned it before, but I think we need to deprecate this first. We can here raise a deprecation warning when unit is None, and still fallback to unit='ns' for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok!
…edelta2 # Conflicts: # pandas/core/tools/timedeltas.py # pandas/tests/indexes/timedeltas/test_partial_slicing.py # pandas/tests/test_resample.py
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -1224,9 +1224,9 @@ Timedelta | |||
- Fixed bug in adding a :class:`DataFrame` with all-`timedelta64[ns]` dtypes to a :class:`DataFrame` with all-integer dtypes returning incorrect results instead of raising ``TypeError`` (:issue:`22696`) | |||
- Bug in :class:`TimedeltaIndex` where adding a timezone-aware datetime scalar incorrectly returned a timezone-naive :class:`DatetimeIndex` (:issue:`23215`) | |||
- Bug in :class:`TimedeltaIndex` where adding ``np.timedelta64('NaT')`` incorrectly returned an all-`NaT` :class:`DatetimeIndex` instead of an all-`NaT` :class:`TimedeltaIndex` (:issue:`23215`) | |||
- Bug in :class:`Timedelta` (and :func: `to_timedelta`) where passing a string of a pure number would not take unit into account. Also raises for ambiguous/duplicate unit specification and a number string without defined unit is deprecated (:issue:`12136`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug in :class:`Timedelta` (and :func: `to_timedelta`) where passing a string of a pure number would not take the unit into account. Now raises for an ambiguous or duplicate unit specification.(:issue:`12136`)
put in the deprecation section
A timedelta passed a number string without a defined unit is deprecated (:issue:`12136`)
pandas/_libs/tslibs/timedeltas.pyx
Outdated
@@ -165,6 +165,8 @@ cpdef convert_to_timedelta64(object ts, object unit): | |||
# kludgy here until we have a timedelta scalar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can make unit=None
in the signature, can you add a doc-string as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, what should I add to the docstring exactly?
pandas/_libs/tslibs/timedeltas.pyx
Outdated
warnings.warn( | ||
"number string without units is deprecated and | ||
" will raise an exception in future versions. Considering as nanoseconds.", | ||
DeprecationWarning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use FutureWarning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!
pandas/_libs/tslibs/timedeltas.pyx
Outdated
return 'ns' | ||
elif unit == 'M': | ||
|
||
# Preserve, will be dealt with eventually in other functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this comment mean? can you reword to reflect your answer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will try with a better comment.
pandas/core/arrays/timedeltas.py
Outdated
@@ -521,6 +521,7 @@ def sequence_to_td64ns(data, copy=False, unit="ns", errors="raise"): | |||
# treat as multiples of the given unit. If after converting to nanos, | |||
# there are fractional components left, these are truncated | |||
# (i.e. NOT rounded) | |||
unit = unit if unit is not None else "ns" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if unit is None:
unit = 'ns'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!
…edelta2 # Conflicts: # doc/source/whatsnew/v0.24.0.rst
can you merge master and i will look |
…edelta2 # Conflicts: # doc/source/whatsnew/v0.24.0.rst # pandas/tests/util/test_hashing.py
can you merge master and update |
can you merge master |
…edelta2 # Conflicts: # doc/source/whatsnew/v0.24.0.rst # pandas/tests/frame/test_arithmetic.py
Waiting for a seemingly bug in pytest |
@Sup3rGeo can you merge master here? Looks like the relevant issue you linked is closed |
can you merge master |
would love to see this, can you merge master and update |
Would be nice but I think this has gone stale. @Sup3rGeo please ping if you'd like to pick this one back up! |
Supersedes #21384.
git diff upstream/master -u -- "*.py" | flake8 --diff