diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 3f1739deb4175..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, Timestamp.now().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,26 +842,27 @@ def test_int_properties(self, arr1d, propname): def test_take_fill_valid(self, arr1d): arr = arr1d dti = self.index_cls(arr1d) + dt_ind = 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" @@ -877,7 +878,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 @@ -1039,14 +1040,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 = 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)