From f5a63f588ab9ae8f4cc74890e072859c9dec841f Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 16 May 2019 20:54:14 +0100 Subject: [PATCH 1/2] FutureWarning difficult to identify source --- doc/source/whatsnew/v0.25.0.rst | 1 + pandas/core/indexes/datetimes.py | 3 ++- pandas/tests/frame/test_alter_axes.py | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index d38ee7b8b589a..a980d2238750f 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -332,6 +332,7 @@ Timezones - Bug in :func:`to_datetime` where an uninformative ``RuntimeError`` was raised when passing a naive :class:`Timestamp` with datetime strings with mixed UTC offsets (:issue:`25978`) - Bug in :func:`to_datetime` with ``unit='ns'`` would drop timezone information from the parsed argument (:issue:`26168`) - Bug in :func:`DataFrame.join` where joining a timezone aware index with a timezone aware column would result in a column of ``NaN`` (:issue:`26335`) +- FutureWarning message raised by :func:`DatetimeIndex.to_series` updated to identify source of warning (:issue:`26329`) Numeric ^^^^^^^ diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 6b9806f4d32f5..9c735a5598f4a 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -689,7 +689,8 @@ def to_series(self, keep_tz=None, index=None, name=None): name = self.name if keep_tz is None and self.tz is not None: - warnings.warn("The default of the 'keep_tz' keyword will change " + warnings.warn("The default of the 'keep_tz' keyword in " + "DatetimeIndex.to_series will change " "to True in a future release. You can set " "'keep_tz=True' to obtain the future behaviour and " "silence this warning.", FutureWarning, stacklevel=2) diff --git a/pandas/tests/frame/test_alter_axes.py b/pandas/tests/frame/test_alter_axes.py index fe347d36d88e7..ab0f17fb4ff13 100644 --- a/pandas/tests/frame/test_alter_axes.py +++ b/pandas/tests/frame/test_alter_axes.py @@ -460,9 +460,13 @@ def test_convert_dti_to_series(self): name='B') tm.assert_series_equal(result, comp) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning) as m: result = idx.to_series(index=[0, 1]) tm.assert_series_equal(result, expected.dt.tz_convert(None)) + msg = ("The default of the 'keep_tz' keyword in " + "DatetimeIndex.to_series will change to True in a future " + "release.") + assert msg in str(m[0].message) with tm.assert_produces_warning(FutureWarning): result = idx.to_series(keep_tz=False, index=[0, 1]) From 1b3bdbf2ae908a834bd934729eeec6d0f434e742 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 17 May 2019 16:10:52 +0100 Subject: [PATCH 2/2] remove whatsnew. not needed. --- doc/source/whatsnew/v0.25.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index a980d2238750f..d38ee7b8b589a 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -332,7 +332,6 @@ Timezones - Bug in :func:`to_datetime` where an uninformative ``RuntimeError`` was raised when passing a naive :class:`Timestamp` with datetime strings with mixed UTC offsets (:issue:`25978`) - Bug in :func:`to_datetime` with ``unit='ns'`` would drop timezone information from the parsed argument (:issue:`26168`) - Bug in :func:`DataFrame.join` where joining a timezone aware index with a timezone aware column would result in a column of ``NaN`` (:issue:`26335`) -- FutureWarning message raised by :func:`DatetimeIndex.to_series` updated to identify source of warning (:issue:`26329`) Numeric ^^^^^^^