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])