From 126a7db53d1649a66efbb0dca6ea16ce2caca50d Mon Sep 17 00:00:00 2001 From: mikhaylov-yv Date: Sun, 14 Nov 2021 16:30:22 +0300 Subject: [PATCH 1/3] Removed Timestamp.now() from tests. --- pandas/tests/arrays/test_datetimelike.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 13fe3c2d427c5..3d5d681485d96 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -168,7 +168,7 @@ def test_take(self): tm.assert_index_equal(self.index_cls(result), expected) - @pytest.mark.parametrize("fill_value", [2, 2.0, Timestamp.now().time]) + @pytest.mark.parametrize("fill_value", [2, 2.0, pd.Timestamp(2021, 1, 1, 12).time]) def test_take_fill_raises(self, fill_value): data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 @@ -844,26 +844,27 @@ def test_int_properties(self, arr1d, propname): def test_take_fill_valid(self, arr1d): arr = arr1d dti = self.index_cls(arr1d) + dt_ind = pd.Timestamp(2021, 1, 1, 12) + dt_ind_tz = dt_ind.tz_localize(dti.tz) - now = Timestamp.now().tz_localize(dti.tz) - result = arr.take([-1, 1], allow_fill=True, fill_value=now) - assert result[0] == now + result = arr.take([-1, 1], allow_fill=True,fill_value=dt_ind_tz) + assert result[0] == dt_ind_tz msg = f"value should be a '{arr1d._scalar_type.__name__}' or 'NaT'. Got" with pytest.raises(TypeError, match=msg): # fill_value Timedelta invalid - arr.take([-1, 1], allow_fill=True, fill_value=now - now) + arr.take([-1, 1], allow_fill=True, fill_value=dt_ind_tz - dt_ind_tz) with pytest.raises(TypeError, match=msg): # fill_value Period invalid arr.take([-1, 1], allow_fill=True, fill_value=Period("2014Q1")) tz = None if dti.tz is not None else "US/Eastern" - now = Timestamp.now().tz_localize(tz) + dt_ind_tz = dt_ind.tz_localize(tz) msg = "Cannot compare tz-naive and tz-aware datetime-like objects" with pytest.raises(TypeError, match=msg): # Timestamp with mismatched tz-awareness - arr.take([-1, 1], allow_fill=True, fill_value=now) + arr.take([-1, 1], allow_fill=True, fill_value=dt_ind_tz) value = NaT.value msg = f"value should be a '{arr1d._scalar_type.__name__}' or 'NaT'. Got" @@ -879,7 +880,7 @@ def test_take_fill_valid(self, arr1d): if arr.tz is not None: # GH#37356 # Assuming here that arr1d fixture does not include Australia/Melbourne - value = Timestamp.now().tz_localize("Australia/Melbourne") + value = dt_ind.tz_localize("Australia/Melbourne") msg = "Timezones don't match. .* != 'Australia/Melbourne'" with pytest.raises(ValueError, match=msg): # require tz match, not just tzawareness match @@ -1041,14 +1042,14 @@ def test_take_fill_valid(self, timedelta_index): result = arr.take([-1, 1], allow_fill=True, fill_value=td1) assert result[0] == td1 - now = Timestamp.now() - value = now + dt_ind = pd.Timestamp(2021, 1, 1, 12) + value = dt_ind msg = f"value should be a '{arr._scalar_type.__name__}' or 'NaT'. Got" with pytest.raises(TypeError, match=msg): # fill_value Timestamp invalid arr.take([0, 1], allow_fill=True, fill_value=value) - value = now.to_period("D") + value = dt_ind.to_period("D") with pytest.raises(TypeError, match=msg): # fill_value Period invalid arr.take([0, 1], allow_fill=True, fill_value=value) From 8ea9a93165c1696a9f0ac6cd4fab46db42e4e904 Mon Sep 17 00:00:00 2001 From: mikhaylov-yv Date: Sun, 14 Nov 2021 17:32:14 +0300 Subject: [PATCH 2/3] Fixes for PEP8 --- pandas/tests/arrays/test_datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 3d5d681485d96..31b789d47f26d 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -847,7 +847,7 @@ def test_take_fill_valid(self, arr1d): dt_ind = pd.Timestamp(2021, 1, 1, 12) dt_ind_tz = dt_ind.tz_localize(dti.tz) - result = arr.take([-1, 1], allow_fill=True,fill_value=dt_ind_tz) + result = arr.take([-1, 1], allow_fill=True, fill_value=dt_ind_tz) assert result[0] == dt_ind_tz msg = f"value should be a '{arr1d._scalar_type.__name__}' or 'NaT'. Got" From 24ff194985e723cbafe6e3aa8f2be1ad7b027b0c Mon Sep 17 00:00:00 2001 From: mikhaylov-yv Date: Mon, 15 Nov 2021 01:53:23 +0300 Subject: [PATCH 3/3] Flake8 Replaced pd.Timestamp () with Timestamp () --- pandas/tests/arrays/test_datetimelike.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index aaad3c720d001..5aa20bedc4a48 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -168,7 +168,7 @@ def test_take(self): tm.assert_index_equal(self.index_cls(result), expected) - @pytest.mark.parametrize("fill_value", [2, 2.0, pd.Timestamp(2021, 1, 1, 12).time]) + @pytest.mark.parametrize("fill_value", [2, 2.0, Timestamp(2021, 1, 1, 12).time]) def test_take_fill_raises(self, fill_value): data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9 @@ -842,7 +842,7 @@ def test_int_properties(self, arr1d, propname): def test_take_fill_valid(self, arr1d): arr = arr1d dti = self.index_cls(arr1d) - dt_ind = pd.Timestamp(2021, 1, 1, 12) + dt_ind = Timestamp(2021, 1, 1, 12) dt_ind_tz = dt_ind.tz_localize(dti.tz) result = arr.take([-1, 1], allow_fill=True, fill_value=dt_ind_tz) @@ -1040,7 +1040,7 @@ def test_take_fill_valid(self, timedelta_index): result = arr.take([-1, 1], allow_fill=True, fill_value=td1) assert result[0] == td1 - dt_ind = pd.Timestamp(2021, 1, 1, 12) + dt_ind = Timestamp(2021, 1, 1, 12) value = dt_ind msg = f"value should be a '{arr._scalar_type.__name__}' or 'NaT'. Got" with pytest.raises(TypeError, match=msg):