Skip to content

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@jreback jreback added Refactor Internal refactoring of code Datetime Datetime data dtype labels May 15, 2022
@jreback jreback added this to the 1.5 milestone May 15, 2022
@jreback
Copy link
Contributor

jreback commented May 15, 2022

looks fine, can you merge master.

cc @mroeschke

@mroeschke
Copy link
Member

Looks like doctests are failing, otherwise LGTM

@jbrockmendel
Copy link
Member Author

The failed doctest looks like the new behavior is just better than the old behavior.

1001     - Finally, mixing timezone-aware strings and :class:`datetime.datetime` always
1002       raises an error, even if the elements all have the same time offset.
1003 
1004     >>> from datetime import datetime, timezone, timedelta
1005     >>> d = datetime(2020, 1, 1, 18, tzinfo=timezone(-timedelta(hours=1)))
1006     >>> pd.to_datetime(["2020-01-01 17:00 -0100", d])
Expected:
    Traceback (most recent call last):
        ...
    ValueError: Tz-aware datetime.datetime cannot be converted to datetime64
                unless utc=True
Got:
    DatetimeIndex(['2020-01-01 17:00:00-01:00', '2020-01-01 18:00:00-01:00'], dtype='datetime64[ns, pytz.FixedOffset(-60)]', freq=None)

@mroeschke
Copy link
Member

Yup agreed. Looks like this example could be removed from the docstring

@mroeschke
Copy link
Member

Or rather, this example this doctest be corrected and added as a unit test

@jreback jreback merged commit 0277a9c into pandas-dev:main May 21, 2022
@jbrockmendel jbrockmendel deleted the ref-array_to_datetime-2 branch May 21, 2022 19:50
@mroeschke
Copy link
Member

@jbrockmendel looks like this is still failing the doc tests

=================================== FAILURES ===================================
______________ [doctest] pandas.core.tools.datetimes.to_datetime _______________
1013 
1014     >>> pd.to_datetime(['2018-10-26 12:00 -0530', '2018-10-26 12:00 -0500'],
1015     ...                utc=True)
1016     DatetimeIndex(['2018-10-26 17:30:00+00:00', '2018-10-26 17:00:00+00:00'],
1017                   dtype='datetime64[ns, UTC]', freq=None)
1018 
1019     - Inputs can contain both naive and aware, string or datetime, the above
1020       rules still apply
1021 
1022     >>> pd.to_datetime(['2018-10-26 12:00', '2018-10-26 12:00 -0530',
UNEXPECTED EXCEPTION: NameError("name 'timezone' is not defined")
Traceback (most recent call last):
  File "/usr/share/miniconda/envs/pandas-dev/lib/python3.8/doctest.py", line 1336, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest pandas.core.tools.datetimes.to_datetime[18]>", line 4, in <module>
NameError: name 'timezone' is not defined
/home/runner/work/pandas/pandas/pandas/core/tools/datetimes.py:1022: UnexpectedException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Datetime Datetime data dtype Refactor Internal refactoring of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants