Skip to content

Commit a56f6ee

Browse files
authored
CI/TST Removed Timestamp.now() from tests. #44341 (#44448)
1 parent d7c5d26 commit a56f6ee

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pandas/tests/arrays/test_datetimelike.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_take(self):
168168

169169
tm.assert_index_equal(self.index_cls(result), expected)
170170

171-
@pytest.mark.parametrize("fill_value", [2, 2.0, Timestamp.now().time])
171+
@pytest.mark.parametrize("fill_value", [2, 2.0, Timestamp(2021, 1, 1, 12).time])
172172
def test_take_fill_raises(self, fill_value):
173173
data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9
174174

@@ -842,26 +842,27 @@ def test_int_properties(self, arr1d, propname):
842842
def test_take_fill_valid(self, arr1d):
843843
arr = arr1d
844844
dti = self.index_cls(arr1d)
845+
dt_ind = Timestamp(2021, 1, 1, 12)
846+
dt_ind_tz = dt_ind.tz_localize(dti.tz)
845847

846-
now = Timestamp.now().tz_localize(dti.tz)
847-
result = arr.take([-1, 1], allow_fill=True, fill_value=now)
848-
assert result[0] == now
848+
result = arr.take([-1, 1], allow_fill=True, fill_value=dt_ind_tz)
849+
assert result[0] == dt_ind_tz
849850

850851
msg = f"value should be a '{arr1d._scalar_type.__name__}' or 'NaT'. Got"
851852
with pytest.raises(TypeError, match=msg):
852853
# fill_value Timedelta invalid
853-
arr.take([-1, 1], allow_fill=True, fill_value=now - now)
854+
arr.take([-1, 1], allow_fill=True, fill_value=dt_ind_tz - dt_ind_tz)
854855

855856
with pytest.raises(TypeError, match=msg):
856857
# fill_value Period invalid
857858
arr.take([-1, 1], allow_fill=True, fill_value=Period("2014Q1"))
858859

859860
tz = None if dti.tz is not None else "US/Eastern"
860-
now = Timestamp.now().tz_localize(tz)
861+
dt_ind_tz = dt_ind.tz_localize(tz)
861862
msg = "Cannot compare tz-naive and tz-aware datetime-like objects"
862863
with pytest.raises(TypeError, match=msg):
863864
# Timestamp with mismatched tz-awareness
864-
arr.take([-1, 1], allow_fill=True, fill_value=now)
865+
arr.take([-1, 1], allow_fill=True, fill_value=dt_ind_tz)
865866

866867
value = NaT.value
867868
msg = f"value should be a '{arr1d._scalar_type.__name__}' or 'NaT'. Got"
@@ -877,7 +878,7 @@ def test_take_fill_valid(self, arr1d):
877878
if arr.tz is not None:
878879
# GH#37356
879880
# Assuming here that arr1d fixture does not include Australia/Melbourne
880-
value = Timestamp.now().tz_localize("Australia/Melbourne")
881+
value = dt_ind.tz_localize("Australia/Melbourne")
881882
msg = "Timezones don't match. .* != 'Australia/Melbourne'"
882883
with pytest.raises(ValueError, match=msg):
883884
# require tz match, not just tzawareness match
@@ -1039,14 +1040,14 @@ def test_take_fill_valid(self, timedelta_index):
10391040
result = arr.take([-1, 1], allow_fill=True, fill_value=td1)
10401041
assert result[0] == td1
10411042

1042-
now = Timestamp.now()
1043-
value = now
1043+
dt_ind = Timestamp(2021, 1, 1, 12)
1044+
value = dt_ind
10441045
msg = f"value should be a '{arr._scalar_type.__name__}' or 'NaT'. Got"
10451046
with pytest.raises(TypeError, match=msg):
10461047
# fill_value Timestamp invalid
10471048
arr.take([0, 1], allow_fill=True, fill_value=value)
10481049

1049-
value = now.to_period("D")
1050+
value = dt_ind.to_period("D")
10501051
with pytest.raises(TypeError, match=msg):
10511052
# fill_value Period invalid
10521053
arr.take([0, 1], allow_fill=True, fill_value=value)

0 commit comments

Comments
 (0)