-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPS: Added tz keyword to to_datetime function, deprecates utc #17413
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 @harpolea! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 01, 2017 at 13:50 Hours UTC |
…ame rather than the timezone
@@ -328,6 +327,10 @@ Deprecations | |||
|
|||
- ``pd.options.html.border`` has been deprecated in favor of ``pd.options.display.html.border`` (:issue:`15793`). | |||
|
|||
|
|||
- :func: `to_datetime` now takes ``tz`` keyword argument, ``utc`` argument is deprecated (:issue:`13712`) |
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.
Say something like (don't copy, make sure to format): The "utc" argument in "to_datetime" has been deprecated in favor of "tz"
@@ -270,6 +270,23 @@ def test_to_datetime_utc_is_true(self): | |||
expected = pd.DatetimeIndex(data=date_range) | |||
tm.assert_index_equal(result, expected) | |||
|
|||
def test_to_datetime_tz_kw(self): |
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.
Make to test the utc
kwarg as being deprecated too.
note that we just merged: #17109 so rebase |
|
||
.. deprecated: 0.21.0 | ||
|
||
tz : pytz.timezone or dateutil.tz.tzfile, default 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.
str is also acceptable
@@ -431,6 +441,10 @@ def _convert_listlike(arg, box, format, name=None, tz=tz): | |||
result = arg | |||
|
|||
if result is None and (format is None or infer_datetime_format): | |||
if tz == 'utc' or tz == 'UTC': |
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.
don't do this, see above
@@ -182,9 +183,12 @@ def _guess_datetime_format_for_array(arr, **kwargs): | |||
return _guess_datetime_format(arr[non_nan_elements[0]], **kwargs) | |||
|
|||
|
|||
@deprecate_kwarg(old_arg_name='utc', new_arg_name='tz', |
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.
instead of doing this, simply translate utc=True
to tz='UTC'
in the code itself (and issue a deprecation warning). Further you will need to raise if utc=True
and tz is not None
, so need a bit more handling (and add a test for this).
|
||
result = pd.to_datetime(data, format='%Y%m%d %H%M%S', tz=tz) | ||
expected = pd.DatetimeIndex(data=date_range) | ||
tm.assert_numpy_array_equal(result.values, expected.values) |
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.
compare index using tm.assert_index_equal
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.
@jreback for some context, the reason I suggested to do it like this is because assert_index_equal fails because timezone localization on single timestamp or on datetimeindex results in a slightly different tz object. This is a separate issue as the the one solved in this pr, therefore suggested this workaround which at least test this is correct (but didn't have time to open an issue, and from phone 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.
we never compare like this - too easy to get wrong; if there is an issue pls show
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 can't test it now, but if I remember correctly: compare pd.Timestamp('2012-01-01', tz='US/Eastern').tz with pd.to_datetime(['2012-01-01']).tz_localize('US/Eastern').tz. Both attributes are not equal
In general, I am wondering whether it is actually needed to deprecate the keyword / worth the trouble for all impacted users. |
why don't we put a DeprecationWanring on utc rather than a FutureWarninhg kind of a soft deprecation |
can you rebase / update |
can u rebase and move note to 0.22 |
can you rebase / move note to 0.22.0 |
closing as stale, but if you'd like to keep working, ping and we can reopen |
git diff upstream/master -u -- "*.py" | flake8 --diff