From bc76a29705393b7ddfa87d5a0aa9427cda8d3683 Mon Sep 17 00:00:00 2001 From: Vladimir Berkutov Date: Thu, 30 Apr 2020 22:07:23 +0100 Subject: [PATCH 1/3] Fix #28552 Add test for DataFrame min/max preserve timezone --- pandas/tests/frame/test_timezones.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandas/tests/frame/test_timezones.py b/pandas/tests/frame/test_timezones.py index dfd4fb1855383..c7ca3f235f818 100644 --- a/pandas/tests/frame/test_timezones.py +++ b/pandas/tests/frame/test_timezones.py @@ -166,3 +166,19 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture): result = DataFrame({"d": [pd.Timestamp("2019", tz=tz)]}, dtype="datetime64[ns]") expected = DataFrame({"d": [pd.Timestamp("2019")]}) tm.assert_frame_equal(result, expected) + + @pytest.mark.parametrize( + "initial", + ["2018-10-08 13:36:45+00:00", "2018-10-08 13:36:45+03:00"], # Non-UTC timezone + ) + @pytest.mark.parametrize("method", [DataFrame.min, DataFrame.max]) + def test_preserve_timezone(self, initial: str, method): + # GH 28552 + # Given + initial_dt = pd.to_datetime(initial) + series = pd.Series([initial_dt]) + df = DataFrame([series]) + # When + actual_df = method(df, axis=1) + # Then + assert actual_df[0].tz == initial_dt.tz From e8268bcc4f5ac8a6fea596df1417c99f33fe0586 Mon Sep 17 00:00:00 2001 From: Vladimir Berkutov Date: Sat, 9 May 2020 22:30:17 +0100 Subject: [PATCH 2/3] #28552 Rename variables in TestDataFrameTimezones.test_preserve_timezone after code review --- pandas/tests/frame/test_timezones.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/test_timezones.py b/pandas/tests/frame/test_timezones.py index c7ca3f235f818..208fe9efbea75 100644 --- a/pandas/tests/frame/test_timezones.py +++ b/pandas/tests/frame/test_timezones.py @@ -171,14 +171,14 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture): "initial", ["2018-10-08 13:36:45+00:00", "2018-10-08 13:36:45+03:00"], # Non-UTC timezone ) - @pytest.mark.parametrize("method", [DataFrame.min, DataFrame.max]) + @pytest.mark.parametrize("method", ["min", "max"]) def test_preserve_timezone(self, initial: str, method): # GH 28552 # Given initial_dt = pd.to_datetime(initial) - series = pd.Series([initial_dt]) - df = DataFrame([series]) + expected = pd.Series([initial_dt]) + df = DataFrame([expected]) # When - actual_df = method(df, axis=1) + result: pd.Series = getattr(df, method)(axis=1) # Then - assert actual_df[0].tz == initial_dt.tz + tm.assert_series_equal(result, expected) From a5295d8255fe41682598cee582c383ec91252698 Mon Sep 17 00:00:00 2001 From: Vladimir Berkutov Date: Tue, 12 May 2020 12:55:18 +0100 Subject: [PATCH 3/3] Fix #28552 Move test to test_analytics.py and clean up --- pandas/tests/frame/test_analytics.py | 13 +++++++++++++ pandas/tests/frame/test_timezones.py | 16 ---------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 0255759513e28..19e355d7f9342 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1246,3 +1246,16 @@ def test_min_max_dt64_with_NaT(self): res = df.max() exp = pd.Series([pd.NaT], index=["foo"]) tm.assert_series_equal(res, exp) + + @pytest.mark.parametrize( + "initial", + ["2018-10-08 13:36:45+00:00", "2018-10-08 13:36:45+03:00"], # Non-UTC timezone + ) + @pytest.mark.parametrize("method", ["min", "max"]) + def test_preserve_timezone(self, initial: str, method): + # GH 28552 + initial_dt = pd.to_datetime(initial) + expected = Series([initial_dt]) + df = DataFrame([expected]) + result = getattr(df, method)(axis=1) + tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/test_timezones.py b/pandas/tests/frame/test_timezones.py index 208fe9efbea75..dfd4fb1855383 100644 --- a/pandas/tests/frame/test_timezones.py +++ b/pandas/tests/frame/test_timezones.py @@ -166,19 +166,3 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture): result = DataFrame({"d": [pd.Timestamp("2019", tz=tz)]}, dtype="datetime64[ns]") expected = DataFrame({"d": [pd.Timestamp("2019")]}) tm.assert_frame_equal(result, expected) - - @pytest.mark.parametrize( - "initial", - ["2018-10-08 13:36:45+00:00", "2018-10-08 13:36:45+03:00"], # Non-UTC timezone - ) - @pytest.mark.parametrize("method", ["min", "max"]) - def test_preserve_timezone(self, initial: str, method): - # GH 28552 - # Given - initial_dt = pd.to_datetime(initial) - expected = pd.Series([initial_dt]) - df = DataFrame([expected]) - # When - result: pd.Series = getattr(df, method)(axis=1) - # Then - tm.assert_series_equal(result, expected)