Skip to content

CI/TST Removed Timestamp.now() from tests. #44341 #44448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down