From f2ab6494a8717a4e77a8d1dccb4fb59f0e89ce86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Thu, 19 Dec 2019 11:09:43 +0100 Subject: [PATCH 01/11] fix test warnings --- pandas/plotting/_matplotlib/misc.py | 2 +- pandas/tests/arrays/test_integer.py | 2 ++ pandas/tests/computation/test_eval.py | 18 ++++++++++++------ pandas/tests/plotting/test_datetimelike.py | 1 + pandas/tests/plotting/test_frame.py | 3 ++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pandas/plotting/_matplotlib/misc.py b/pandas/plotting/_matplotlib/misc.py index 0720f544203f7..1c3e60ae8551a 100644 --- a/pandas/plotting/_matplotlib/misc.py +++ b/pandas/plotting/_matplotlib/misc.py @@ -210,7 +210,7 @@ def f(t): # appropriately. Take a copy of amplitudes as otherwise numpy # deletes the element from amplitudes itself. coeffs = np.delete(np.copy(amplitudes), 0) - coeffs.resize(int((coeffs.size + 1) / 2), 2) + coeffs.resize(int((coeffs.size + 1) / 2), 2, refcheck=False) # Generate the harmonics and arguments for the sin and cos # functions. diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index 7bb0b065df1da..32e956c7d7118 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -827,6 +827,8 @@ def test_astype_nansafe(): @pytest.mark.parametrize("ufunc", [np.abs, np.sign]) +# np.sign emits a warning with nans, +@pytest.mark.filterwarnings("ignore:invalid value encountered in sign") def test_ufuncs_single_int(ufunc): a = integer_array([1, 2, -3, np.nan]) result = ufunc(a) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 2208fbf933387..95485ec2ed885 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -1210,25 +1210,31 @@ def test_truediv(self): ex = "s / 1" d = {"s": s} # noqa - res = self.eval(ex, truediv=False) + with pytest.warns(FutureWarning): + res = self.eval(ex, truediv=False) tm.assert_numpy_array_equal(res, np.array([1.0])) - res = self.eval(ex, truediv=True) + with pytest.warns(FutureWarning): + res = self.eval(ex, truediv=True) tm.assert_numpy_array_equal(res, np.array([1.0])) - res = self.eval("1 / 2", truediv=True) + with pytest.warns(FutureWarning): + res = self.eval("1 / 2", truediv=True) expec = 0.5 assert res == expec - res = self.eval("1 / 2", truediv=False) + with pytest.warns(FutureWarning): + res = self.eval("1 / 2", truediv=False) expec = 0.5 assert res == expec - res = self.eval("s / 2", truediv=False) + with pytest.warns(FutureWarning): + res = self.eval("s / 2", truediv=False) expec = 0.5 assert res == expec - res = self.eval("s / 2", truediv=True) + with pytest.warns(FutureWarning): + res = self.eval("s / 2", truediv=True) expec = 0.5 assert res == expec diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 8456f095e5868..b1bd639d4bac7 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -44,6 +44,7 @@ def teardown_method(self, method): tm.close() @pytest.mark.slow + @pytest.mark.filterwarnings("ignore:Converting to PeriodArray/Index representation will drop timezone information.") def test_ts_plot_with_tz(self, tz_aware_fixture): # GH2877, GH17173 tz = tz_aware_fixture diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index fd66888fc30e4..54ca43efa5753 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -538,7 +538,8 @@ def test_subplots_timeseries_y_axis(self): ax_datetime_no_tz.get_lines()[0].get_data()[1] == testdata["datetime_no_tz"].values ).all() - ax_datetime_all_tz = testdata.plot(y="datetime_all_tz") + with pytest.warns(FutureWarning): + ax_datetime_all_tz = testdata.plot(y="datetime_all_tz") assert ( ax_datetime_all_tz.get_lines()[0].get_data()[1] == testdata["datetime_all_tz"].values From 126123f9e609f590d0adf4284c494357b9c877a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Thu, 19 Dec 2019 11:13:01 +0100 Subject: [PATCH 02/11] fix line-too-long --- pandas/tests/plotting/test_datetimelike.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index b1bd639d4bac7..a26ffee732598 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -44,7 +44,10 @@ def teardown_method(self, method): tm.close() @pytest.mark.slow - @pytest.mark.filterwarnings("ignore:Converting to PeriodArray/Index representation will drop timezone information.") + @pytest.mark.filterwarnings( + "ignore:Converting to PeriodArray/Index representation " + "will drop timezone information." + ) def test_ts_plot_with_tz(self, tz_aware_fixture): # GH2877, GH17173 tz = tz_aware_fixture From 2d8b01c6c5e2b488318def59552eafe01c53f676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Thu, 19 Dec 2019 11:18:32 +0100 Subject: [PATCH 03/11] pytest.warns -> tm.assert_produces_warning --- pandas/tests/computation/test_eval.py | 12 ++++++------ pandas/tests/plotting/test_frame.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 95485ec2ed885..266d1d36720a8 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -1210,30 +1210,30 @@ def test_truediv(self): ex = "s / 1" d = {"s": s} # noqa - with pytest.warns(FutureWarning): + with tm.assert_produces_warning(FutureWarning): res = self.eval(ex, truediv=False) tm.assert_numpy_array_equal(res, np.array([1.0])) - with pytest.warns(FutureWarning): + with tm.assert_produces_warning(FutureWarning): res = self.eval(ex, truediv=True) tm.assert_numpy_array_equal(res, np.array([1.0])) - with pytest.warns(FutureWarning): + with tm.assert_produces_warning(FutureWarning): res = self.eval("1 / 2", truediv=True) expec = 0.5 assert res == expec - with pytest.warns(FutureWarning): + with tm.assert_produces_warning(FutureWarning): res = self.eval("1 / 2", truediv=False) expec = 0.5 assert res == expec - with pytest.warns(FutureWarning): + with tm.assert_produces_warning(FutureWarning): res = self.eval("s / 2", truediv=False) expec = 0.5 assert res == expec - with pytest.warns(FutureWarning): + with tm.assert_produces_warning(FutureWarning): res = self.eval("s / 2", truediv=True) expec = 0.5 assert res == expec diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 54ca43efa5753..320a41a4ccfeb 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -538,7 +538,7 @@ def test_subplots_timeseries_y_axis(self): ax_datetime_no_tz.get_lines()[0].get_data()[1] == testdata["datetime_no_tz"].values ).all() - with pytest.warns(FutureWarning): + with tm.assert_produces_warning(FutureWarning): ax_datetime_all_tz = testdata.plot(y="datetime_all_tz") assert ( ax_datetime_all_tz.get_lines()[0].get_data()[1] From 273cd065eef007c1633b7e10f9cf4ff65ace93a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Thu, 19 Dec 2019 11:54:55 +0100 Subject: [PATCH 04/11] don't check stacklevel on warnings test --- pandas/tests/plotting/test_frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 320a41a4ccfeb..40be4463ac029 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -538,7 +538,7 @@ def test_subplots_timeseries_y_axis(self): ax_datetime_no_tz.get_lines()[0].get_data()[1] == testdata["datetime_no_tz"].values ).all() - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): ax_datetime_all_tz = testdata.plot(y="datetime_all_tz") assert ( ax_datetime_all_tz.get_lines()[0].get_data()[1] From 381ad46460156ba7904b4de5f6622a8a50f7fe3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 20 Dec 2019 17:38:23 +0100 Subject: [PATCH 05/11] better warning interception in test_datetimelike.py --- pandas/tests/plotting/test_datetimelike.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index a26ffee732598..acab326ca8994 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1,10 +1,12 @@ """ Test cases for time series specific (freq conversion, etc) """ -from datetime import date, datetime, time, timedelta +from datetime import date, datetime, time, timedelta, timezone +import dateutil import pickle import sys import numpy as np import pytest +import pytz import pandas.util._test_decorators as td @@ -44,16 +46,21 @@ def teardown_method(self, method): tm.close() @pytest.mark.slow - @pytest.mark.filterwarnings( - "ignore:Converting to PeriodArray/Index representation " - "will drop timezone information." - ) def test_ts_plot_with_tz(self, tz_aware_fixture): # GH2877, GH17173 tz = tz_aware_fixture index = date_range("1/1/2011", periods=2, freq="H", tz=tz) ts = Series([188.5, 328.25], index=index) - _check_plot_works(ts.plot) + if ( + tz in ["UTC", pytz.UTC, timezone.utc] + or isinstance(tz, dateutil.tz.tz.tzutc) + ): + # Converting to PeriodArray/Index representation will drop timezone + # information. + with tm.assert_produces_warning(UserWarning): + _check_plot_works(ts.plot) + else: + _check_plot_works(ts.plot) def test_fontsize_set_correctly(self): # For issue #8765 From 11536f29cd86e9041b589de7e0ab06e60238a456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 20 Dec 2019 17:47:47 +0100 Subject: [PATCH 06/11] add descriptions to some warning interceptors --- pandas/tests/computation/test_eval.py | 2 ++ pandas/tests/plotting/test_frame.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 266d1d36720a8..ab214df558900 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -1210,6 +1210,8 @@ def test_truediv(self): ex = "s / 1" d = {"s": s} # noqa + # FutureWarning: The `truediv` parameter in pd.eval is deprecated and will be + # removed in a future version. with tm.assert_produces_warning(FutureWarning): res = self.eval(ex, truediv=False) tm.assert_numpy_array_equal(res, np.array([1.0])) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 40be4463ac029..6c70280689cca 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -538,6 +538,10 @@ def test_subplots_timeseries_y_axis(self): ax_datetime_no_tz.get_lines()[0].get_data()[1] == testdata["datetime_no_tz"].values ).all() + # FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive + # ndarray with 'datetime64[ns]' dtype. In the future, this will return an + # ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with + # the correct 'tz'. with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): ax_datetime_all_tz = testdata.plot(y="datetime_all_tz") assert ( From f231957b0f2b1beef2e2539f3f3d8c0df947cf35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 20 Dec 2019 18:23:53 +0100 Subject: [PATCH 07/11] isort --- pandas/tests/plotting/test_datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index acab326ca8994..003cdbd8a3e78 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1,9 +1,9 @@ """ Test cases for time series specific (freq conversion, etc) """ from datetime import date, datetime, time, timedelta, timezone -import dateutil import pickle import sys +import dateutil import numpy as np import pytest import pytz From 398811b854dc42e4261c15a11011d2295126322c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 20 Dec 2019 20:46:28 +0100 Subject: [PATCH 08/11] make black --- pandas/tests/plotting/test_datetimelike.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 003cdbd8a3e78..7a7a558e80330 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -51,9 +51,8 @@ def test_ts_plot_with_tz(self, tz_aware_fixture): tz = tz_aware_fixture index = date_range("1/1/2011", periods=2, freq="H", tz=tz) ts = Series([188.5, 328.25], index=index) - if ( - tz in ["UTC", pytz.UTC, timezone.utc] - or isinstance(tz, dateutil.tz.tz.tzutc) + if tz in ["UTC", pytz.UTC, timezone.utc] or isinstance( + tz, dateutil.tz.tz.tzutc ): # Converting to PeriodArray/Index representation will drop timezone # information. From 1b4c8c1cb93dea9262ffb90fcdc999f3080dc732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Mon, 23 Dec 2019 23:58:12 +0100 Subject: [PATCH 09/11] revert refcheck=False --- pandas/plotting/_matplotlib/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/misc.py b/pandas/plotting/_matplotlib/misc.py index 1c3e60ae8551a..0720f544203f7 100644 --- a/pandas/plotting/_matplotlib/misc.py +++ b/pandas/plotting/_matplotlib/misc.py @@ -210,7 +210,7 @@ def f(t): # appropriately. Take a copy of amplitudes as otherwise numpy # deletes the element from amplitudes itself. coeffs = np.delete(np.copy(amplitudes), 0) - coeffs.resize(int((coeffs.size + 1) / 2), 2, refcheck=False) + coeffs.resize(int((coeffs.size + 1) / 2), 2) # Generate the harmonics and arguments for the sin and cos # functions. From 1a9b188097e3e094af306fc73621f71ad650207f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 3 Jan 2020 09:28:50 +0100 Subject: [PATCH 10/11] ignore warning --- pandas/tests/plotting/test_datetimelike.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 7a7a558e80330..0904d72d12147 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1,12 +1,10 @@ """ Test cases for time series specific (freq conversion, etc) """ -from datetime import date, datetime, time, timedelta, timezone +from datetime import date, datetime, time, timedelta import pickle import sys -import dateutil import numpy as np import pytest -import pytz import pandas.util._test_decorators as td @@ -45,21 +43,19 @@ def setup_method(self, method): def teardown_method(self, method): tm.close() + # Ignore warning + # ``` + # Converting to PeriodArray/Index representation will drop timezone information. + # ``` + # which occurs for UTC-like timezones. @pytest.mark.slow + @pytest.mark.filterwarnings("ignore:msg:UserWarning") def test_ts_plot_with_tz(self, tz_aware_fixture): # GH2877, GH17173 tz = tz_aware_fixture index = date_range("1/1/2011", periods=2, freq="H", tz=tz) ts = Series([188.5, 328.25], index=index) - if tz in ["UTC", pytz.UTC, timezone.utc] or isinstance( - tz, dateutil.tz.tz.tzutc - ): - # Converting to PeriodArray/Index representation will drop timezone - # information. - with tm.assert_produces_warning(UserWarning): - _check_plot_works(ts.plot) - else: - _check_plot_works(ts.plot) + _check_plot_works(ts.plot) def test_fontsize_set_correctly(self): # For issue #8765 From 44f77935f041a501042d83842e6d98743e1813d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Mon, 20 Jan 2020 20:26:45 +0100 Subject: [PATCH 11/11] remove FutureWarning requirement (has been fixed in pandas) --- pandas/tests/plotting/test_frame.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 64e45fea7da4d..1c429bafa9a19 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -538,12 +538,7 @@ def test_subplots_timeseries_y_axis(self): ax_datetime_no_tz.get_lines()[0].get_data()[1] == testdata["datetime_no_tz"].values ).all() - # FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive - # ndarray with 'datetime64[ns]' dtype. In the future, this will return an - # ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with - # the correct 'tz'. - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - ax_datetime_all_tz = testdata.plot(y="datetime_all_tz") + ax_datetime_all_tz = testdata.plot(y="datetime_all_tz") assert ( ax_datetime_all_tz.get_lines()[0].get_data()[1] == testdata["datetime_all_tz"].values