Skip to content

BUG: date_range doesn't propagate ambigous=False to tz_localize #35302

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

Merged
merged 15 commits into from
Aug 1, 2020
Merged
1 change: 0 additions & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,6 @@ Timezones
^^^^^^^^^

- Bug in :func:`to_datetime` with ``infer_datetime_format=True`` where timezone names (e.g. ``UTC``) would not be parsed correctly (:issue:`33133`)
-


Numeric
Expand Down
210 changes: 210 additions & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
.. _whatsnew_120:

What's new in 1.2.0 (??)
------------------------

These are the changes in pandas 1.2.0. See :ref:`release` for a full changelog
including other versions of pandas.

{{ header }}

.. ---------------------------------------------------------------------------

Enhancements
~~~~~~~~~~~~


.. _whatsnew_120.enhancements.other:

Other enhancements
^^^^^^^^^^^^^^^^^^

.. ---------------------------------------------------------------------------

.. _whatsnew_120.notable_bug_fixes:

Notable bug fixes
~~~~~~~~~~~~~~~~~

These are bug fixes that might have notable behavior changes.


Increased minimum versions for dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Some minimum supported versions of dependencies were updated ().
If installed, we now require:

+-----------------+-----------------+----------+---------+
| Package | Minimum Version | Required | Changed |
+=================+=================+==========+=========+
| numpy | 1.15.4 | X | |
+-----------------+-----------------+----------+---------+
| pytz | 2015.4 | X | |
+-----------------+-----------------+----------+---------+
| python-dateutil | 2.7.3 | X | |
+-----------------+-----------------+----------+---------+
| bottleneck | 1.2.1 | | |
+-----------------+-----------------+----------+---------+
| numexpr | 2.6.2 | | |
+-----------------+-----------------+----------+---------+
| pytest (dev) | 4.0.2 | | |
+-----------------+-----------------+----------+---------+

For `optional libraries <https://dev.pandas.io/docs/install.html#dependencies>`_ the general recommendation is to use the latest version.
The following table lists the lowest version per library that is currently being tested throughout the development of pandas.
Optional libraries below the lowest tested version may still work, but are not considered supported.

+-----------------+-----------------+---------+
| Package | Minimum Version | Changed |
+=================+=================+=========+
| beautifulsoup4 | 4.6.0 | |
+-----------------+-----------------+---------+
| fastparquet | 0.3.2 | |
+-----------------+-----------------+---------+
| fsspec | 0.7.4 | |
+-----------------+-----------------+---------+
| gcsfs | 0.6.0 | |
+-----------------+-----------------+---------+
| lxml | 3.8.0 | |
+-----------------+-----------------+---------+
| matplotlib | 2.2.2 | |
+-----------------+-----------------+---------+
| numba | 0.46.0 | |
+-----------------+-----------------+---------+
| openpyxl | 2.5.7 | |
+-----------------+-----------------+---------+
| pyarrow | 0.13.0 | |
+-----------------+-----------------+---------+
| pymysql | 0.7.1 | |
+-----------------+-----------------+---------+
| pytables | 3.4.3 | |
+-----------------+-----------------+---------+
| s3fs | 0.4.0 | |
+-----------------+-----------------+---------+
| scipy | 1.2.0 | |
+-----------------+-----------------+---------+
| sqlalchemy | 1.1.4 | |
+-----------------+-----------------+---------+
| xarray | 0.8.2 | |
+-----------------+-----------------+---------+
| xlrd | 1.1.0 | |
+-----------------+-----------------+---------+
| xlsxwriter | 0.9.8 | |
+-----------------+-----------------+---------+
| xlwt | 1.2.0 | |
+-----------------+-----------------+---------+
| pandas-gbq | 1.2.0 | |
+-----------------+-----------------+---------+

See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more.

Development Changes
^^^^^^^^^^^^^^^^^^^

-

.. _whatsnew_120.deprecations:

Deprecations
~~~~~~~~~~~~

-

.. ---------------------------------------------------------------------------


.. _whatsnew_120.performance:

Performance improvements
~~~~~~~~~~~~~~~~~~~~~~~~

-

.. ---------------------------------------------------------------------------

.. _whatsnew_120.bug_fixes:

Bug fixes
~~~~~~~~~


Categorical
^^^^^^^^^^^
-

Datetimelike
^^^^^^^^^^^^
-

Timedelta
^^^^^^^^^
-

Timezones
^^^^^^^^^
- Bug in :func:`date_range` was raising AmbiguousTimeError for valid input with `ambiguous=False` (:issue:`35297`)

Numeric
^^^^^^^
-

Conversion
^^^^^^^^^^
-

Strings
^^^^^^^
-

Interval
^^^^^^^^
-

Indexing
^^^^^^^^
-

Missing
^^^^^^^
-

MultiIndex
^^^^^^^^^^
-

I/O
^^^
-

Plotting
^^^^^^^^
-

Groupby/resample/rolling
^^^^^^^^^^^^^^^^^^^^^^^^
-

Reshaping
^^^^^^^^^
-

Sparse
^^^^^^
-

ExtensionArray
^^^^^^^^^^^^^^
-

Other
^^^^^
-

.. ---------------------------------------------------------------------------

.. _whatsnew_120.contributors:

Contributors
~~~~~~~~~~~~

4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ def _generate_range(
# index is localized datetime64 array -> have to convert
# start/end as well to compare
if start is not None:
start = start.tz_localize(tz).asm8
start = start.tz_localize(tz, ambiguous, nonexistent).asm8
if end is not None:
end = end.tz_localize(tz).asm8
end = end.tz_localize(tz, ambiguous, nonexistent).asm8
else:
# Create a linearly spaced date_range in local time
# Nanosecond-granularity timestamps aren't always correctly
Expand Down
59 changes: 59 additions & 0 deletions pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,65 @@ def test_construction_with_nat_and_tzlocal(self):
expected = DatetimeIndex([Timestamp("2018", tz=tz), pd.NaT])
tm.assert_index_equal(result, expected)

def test_constructor_with_ambiguous_keyword_arg(self):
# GH 35297

expected = DatetimeIndex(
["2020-11-01 01:00:00", "2020-11-02 01:00:00"],
dtype="datetime64[ns, America/New_York]",
freq="D",
ambiguous=False,
)

# ambiguous keyword in start
timezone = "America/New_York"
start = pd.Timestamp(year=2020, month=11, day=1, hour=1).tz_localize(
timezone, ambiguous=False
)
result = pd.date_range(start=start, periods=2, ambiguous=False)
tm.assert_index_equal(result, expected)

# ambiguous keyword in end
timezone = "America/New_York"
end = pd.Timestamp(year=2020, month=11, day=2, hour=1).tz_localize(
timezone, ambiguous=False
)
result = pd.date_range(end=end, periods=2, ambiguous=False)
tm.assert_index_equal(result, expected)

def test_constructor_with_nonexistent_keyword_arg(self):
# GH 35297

timezone = "Europe/Warsaw"

# nonexistent keyword in start
start = pd.Timestamp("2015-03-29 02:30:00").tz_localize(
timezone, nonexistent="shift_forward"
)
result = pd.date_range(start=start, periods=2, freq="H")
expected = DatetimeIndex(
[
pd.Timestamp("2015-03-29 03:00:00+02:00", tz=timezone),
pd.Timestamp("2015-03-29 04:00:00+02:00", tz=timezone),
]
)

tm.assert_index_equal(result, expected)

# nonexistent keyword in end
end = pd.Timestamp("2015-03-29 02:30:00").tz_localize(
timezone, nonexistent="shift_forward"
)
result = pd.date_range(end=end, periods=2, freq="H")
expected = DatetimeIndex(
[
pd.Timestamp("2015-03-29 01:00:00+01:00", tz=timezone),
pd.Timestamp("2015-03-29 03:00:00+02:00", tz=timezone),
]
)

tm.assert_index_equal(result, expected)

def test_constructor_no_precision_raises(self):
# GH-24753, GH-24739

Expand Down