Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

harpolea
Copy link

@harpolea harpolea commented Sep 1, 2017

@pep8speaks
Copy link

pep8speaks commented Sep 1, 2017

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

@gfyoung gfyoung added Compat pandas objects compatability with Numpy or Python functions Deprecate Functionality to remove in pandas Datetime Datetime data dtype labels Sep 1, 2017
@@ -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`)
Copy link
Member

@gfyoung gfyoung Sep 1, 2017

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):
Copy link
Member

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.

@jreback
Copy link
Contributor

jreback commented Sep 1, 2017

note that we just merged: #17109

so rebase


.. deprecated: 0.21.0

tz : pytz.timezone or dateutil.tz.tzfile, default None
Copy link
Contributor

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':
Copy link
Contributor

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',
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Member

@jorisvandenbossche jorisvandenbossche Sep 2, 2017

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)

Copy link
Contributor

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

Copy link
Member

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

@jorisvandenbossche
Copy link
Member

In general, I am wondering whether it is actually needed to deprecate the keyword / worth the trouble for all impacted users.
I am certainly + 1 on adding tz keyword. But we can keep utc=True just as an alias for tz='utc'

@jreback
Copy link
Contributor

jreback commented Sep 2, 2017

why don't we put a DeprecationWanring on utc rather than a FutureWarninhg

kind of a soft deprecation

@jreback
Copy link
Contributor

jreback commented Sep 23, 2017

can you rebase / update

@jreback
Copy link
Contributor

jreback commented Oct 28, 2017

can u rebase and move note to 0.22

@jreback
Copy link
Contributor

jreback commented Nov 12, 2017

can you rebase / move note to 0.22.0

@jreback
Copy link
Contributor

jreback commented Dec 10, 2017

closing as stale, but if you'd like to keep working, ping and we can reopen

@jreback jreback closed this Dec 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Datetime Datetime data dtype Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tz kw to to_datetime, deprecate utc
5 participants