diff --git a/pandas/conftest.py b/pandas/conftest.py index 7bc6dbae38e6c..04589993b5f53 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -1268,6 +1268,16 @@ def timedelta64_dtype(request): return request.param +@pytest.fixture +def fixed_now_ts(): + """ + Fixture emits fixed Timestamp.now() + """ + return Timestamp( + year=2021, month=1, day=1, hour=12, minute=4, second=13, microsecond=22 + ) + + @pytest.fixture(params=tm.FLOAT_NUMPY_DTYPES) def float_numpy_dtype(request): """ diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index 87bbdfb3c808f..49585f3d37924 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -150,7 +150,7 @@ def test_dt64arr_nat_comparison(self, tz_naive_fixture, box_with_array): tz = tz_naive_fixture box = box_with_array - ts = Timestamp.now(tz) + ts = Timestamp("2021-01-01", tz=tz) ser = Series([ts, NaT]) obj = tm.box_expected(ser, box) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 3bf5fdb257c2a..a33febbfbe960 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -85,9 +85,9 @@ def test_operator_series_comparison_zerorank(self): expected = 0.0 > Series([1, 2, 3]) tm.assert_series_equal(result, expected) - def test_df_numeric_cmp_dt64_raises(self, box_with_array): + def test_df_numeric_cmp_dt64_raises(self, box_with_array, fixed_now_ts): # GH#8932, GH#22163 - ts = pd.Timestamp.now() + ts = fixed_now_ts obj = np.array(range(5)) obj = tm.box_expected(obj, box_with_array) @@ -281,9 +281,9 @@ def test_add_sub_timedeltalike_invalid(self, numeric_idx, other, box_with_array) @pytest.mark.parametrize( "other", [ - pd.Timestamp.now().to_pydatetime(), - pd.Timestamp.now(tz="UTC").to_pydatetime(), - pd.Timestamp.now().to_datetime64(), + pd.Timestamp("2021-01-01").to_pydatetime(), + pd.Timestamp("2021-01-01", tz="UTC").to_pydatetime(), + pd.Timestamp("2021-01-01").to_datetime64(), pd.NaT, ], ) @@ -873,7 +873,7 @@ def test_add_frames(self, first, second, expected): tm.assert_frame_equal(second + first, expected) # TODO: This came from series.test.test_operators, needs cleanup - def test_series_frame_radd_bug(self): + def test_series_frame_radd_bug(self, fixed_now_ts): # GH#353 vals = Series(tm.rands_array(5, 10)) result = "foo_" + vals @@ -889,7 +889,7 @@ def test_series_frame_radd_bug(self): ts.name = "ts" # really raise this time - now = pd.Timestamp.now().to_pydatetime() + fix_now = fixed_now_ts.to_pydatetime() msg = "|".join( [ "unsupported operand type", @@ -898,10 +898,10 @@ def test_series_frame_radd_bug(self): ] ) with pytest.raises(TypeError, match=msg): - now + ts + fix_now + ts with pytest.raises(TypeError, match=msg): - ts + now + ts + fix_now # TODO: This came from series.test.test_operators, needs cleanup def test_datetime64_with_index(self): diff --git a/pandas/tests/arithmetic/test_object.py b/pandas/tests/arithmetic/test_object.py index 3069868ebb677..c96d7c01ec97f 100644 --- a/pandas/tests/arithmetic/test_object.py +++ b/pandas/tests/arithmetic/test_object.py @@ -315,7 +315,7 @@ def test_sub_object(self): with pytest.raises(TypeError, match=msg): index - np.array([2, "foo"], dtype=object) - def test_rsub_object(self): + def test_rsub_object(self, fixed_now_ts): # GH#19369 index = pd.Index([Decimal(1), Decimal(2)]) expected = pd.Index([Decimal(1), Decimal(0)]) @@ -331,7 +331,7 @@ def test_rsub_object(self): "foo" - index with pytest.raises(TypeError, match=msg): - np.array([True, Timestamp.now()]) - index + np.array([True, fixed_now_ts]) - index class MyIndex(pd.Index): diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index f4404a3483e6f..a231e52d4b027 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -72,7 +72,7 @@ def test_compare_zerodim(self, box_with_array): "scalar", [ "foo", - Timestamp.now(), + Timestamp("2021-01-01"), Timedelta(days=4), 9, 9.5, @@ -693,9 +693,9 @@ def test_sub_n_gt_1_offsets(self, offset, kwd_name, n): "other", [ # datetime scalars - Timestamp.now(), - Timestamp.now().to_pydatetime(), - Timestamp.now().to_datetime64(), + Timestamp("2016-01-01"), + Timestamp("2016-01-01").to_pydatetime(), + Timestamp("2016-01-01").to_datetime64(), # datetime-like arrays pd.date_range("2016-01-01", periods=3, freq="H"), pd.date_range("2016-01-01", periods=3, tz="Europe/Brussels"), diff --git a/pandas/tests/arithmetic/test_timedelta64.py b/pandas/tests/arithmetic/test_timedelta64.py index 93332b9b96f84..29c01e45ed28d 100644 --- a/pandas/tests/arithmetic/test_timedelta64.py +++ b/pandas/tests/arithmetic/test_timedelta64.py @@ -110,11 +110,11 @@ def test_compare_timedeltalike_scalar(self, box_with_array, td_scalar): [ 345600000000000, "a", - Timestamp.now(), - Timestamp.now("UTC"), - Timestamp.now().to_datetime64(), - Timestamp.now().to_pydatetime(), - Timestamp.now().date(), + Timestamp("2021-01-01"), + Timestamp("2021-01-01").now("UTC"), + Timestamp("2021-01-01").now().to_datetime64(), + Timestamp("2021-01-01").now().to_pydatetime(), + Timestamp("2021-01-01").date(), np.array(4), # zero-dim mismatched dtype ], ) @@ -152,7 +152,7 @@ def test_td64arr_cmp_arraylike_invalid(self, other, box_with_array): def test_td64arr_cmp_mixed_invalid(self): rng = timedelta_range("1 days", periods=5)._data - other = np.array([0, 1, 2, rng[3], Timestamp.now()]) + other = np.array([0, 1, 2, rng[3], Timestamp("2021-01-01")]) result = rng == other expected = np.array([False, False, False, True, False]) @@ -2174,7 +2174,7 @@ def test_td64arr_pow_invalid(self, scalar_td, box_with_array): def test_add_timestamp_to_timedelta(): # GH: 35897 - timestamp = Timestamp.now() + timestamp = Timestamp("2021-01-01") result = timestamp + timedelta_range("0s", "1s", periods=31) expected = DatetimeIndex( [ diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index 092fc6a460fca..c330e959ad5bf 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -539,7 +539,7 @@ def test_to_numpy_na_value(dtype, nulls_fixture): tm.assert_numpy_array_equal(result, expected) -def test_isin(dtype, request): +def test_isin(dtype, request, fixed_now_ts): s = pd.Series(["a", "b", None], dtype=dtype) result = s.isin(["a", "c"]) @@ -554,6 +554,6 @@ def test_isin(dtype, request): expected = pd.Series([False, False, False]) tm.assert_series_equal(result, expected) - result = s.isin(["a", pd.Timestamp.now()]) + result = s.isin(["a", fixed_now_ts]) expected = pd.Series([True, False, False]) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index ff7c7a7782da3..00a8110a399d4 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -839,30 +839,29 @@ def test_int_properties(self, arr1d, propname): tm.assert_numpy_array_equal(result, expected) - def test_take_fill_valid(self, arr1d): + def test_take_fill_valid(self, arr1d, fixed_now_ts): arr = arr1d dti = self.index_cls(arr1d) - 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) - assert result[0] == dt_ind_tz + now = fixed_now_ts.tz_localize(dti.tz) + result = arr.take([-1, 1], allow_fill=True, fill_value=now) + assert result[0] == now 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=dt_ind_tz - dt_ind_tz) + arr.take([-1, 1], allow_fill=True, fill_value=now - now) 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" - dt_ind_tz = dt_ind.tz_localize(tz) + now = fixed_now_ts.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=dt_ind_tz) + arr.take([-1, 1], allow_fill=True, fill_value=now) value = NaT.value msg = f"value should be a '{arr1d._scalar_type.__name__}' or 'NaT'. Got" @@ -878,7 +877,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 = dt_ind.tz_localize("Australia/Melbourne") + value = fixed_now_ts.tz_localize("Australia/Melbourne") msg = "Timezones don't match. .* != 'Australia/Melbourne'" with pytest.raises(ValueError, match=msg): # require tz match, not just tzawareness match @@ -1032,7 +1031,7 @@ def test_array_interface(self, timedelta_index): expected = np.asarray(arr).astype(dtype) tm.assert_numpy_array_equal(result, expected) - def test_take_fill_valid(self, timedelta_index): + def test_take_fill_valid(self, timedelta_index, fixed_now_ts): tdi = timedelta_index arr = TimedeltaArray(tdi) @@ -1040,14 +1039,13 @@ 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 = Timestamp(2021, 1, 1, 12) - value = dt_ind + value = fixed_now_ts 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 = dt_ind.to_period("D") + value = fixed_now_ts.to_period("D") with pytest.raises(TypeError, match=msg): # fill_value Period invalid arr.take([0, 1], allow_fill=True, fill_value=value) diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 0453b1ef1c40d..d905c55c4553a 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -146,9 +146,9 @@ def test_setitem_clears_freq(self): @pytest.mark.parametrize( "obj", [ - pd.Timestamp.now(), - pd.Timestamp.now().to_datetime64(), - pd.Timestamp.now().to_pydatetime(), + pd.Timestamp("2021-01-01"), + pd.Timestamp("2021-01-01").to_datetime64(), + pd.Timestamp("2021-01-01").to_pydatetime(), ], ) def test_setitem_objects(self, obj): @@ -329,7 +329,7 @@ def test_searchsorted_tzawareness_compat(self, index): "invalid", np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9, np.arange(10).view("timedelta64[ns]") * 24 * 3600 * 10 ** 9, - pd.Timestamp.now().to_period("D"), + pd.Timestamp("2021-01-01").to_period("D"), ], ) @pytest.mark.parametrize("index", [True, False]) diff --git a/pandas/tests/arrays/test_timedeltas.py b/pandas/tests/arrays/test_timedeltas.py index 10d12446666ce..b9ddac92c0a47 100644 --- a/pandas/tests/arrays/test_timedeltas.py +++ b/pandas/tests/arrays/test_timedeltas.py @@ -55,11 +55,11 @@ def test_setitem_objects(self, obj): np.int64(1), 1.0, np.datetime64("NaT"), - pd.Timestamp.now(), + pd.Timestamp("2021-01-01"), "invalid", np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9, (np.arange(10) * 24 * 3600 * 10 ** 9).view("datetime64[ns]"), - pd.Timestamp.now().to_period("D"), + pd.Timestamp("2021-01-01").to_period("D"), ], ) @pytest.mark.parametrize("index", [True, False]) diff --git a/pandas/tests/arrays/timedeltas/test_reductions.py b/pandas/tests/arrays/timedeltas/test_reductions.py index 9e854577f7e3c..586a9187fc169 100644 --- a/pandas/tests/arrays/timedeltas/test_reductions.py +++ b/pandas/tests/arrays/timedeltas/test_reductions.py @@ -127,9 +127,9 @@ def test_sum_2d_skipna_false(self): "add", [ Timedelta(0), - pd.Timestamp.now(), - pd.Timestamp.now("UTC"), - pd.Timestamp.now("Asia/Tokyo"), + pd.Timestamp("2021-01-01"), + pd.Timestamp("2021-01-01", tz="UTC"), + pd.Timestamp("2021-01-01", tz="Asia/Tokyo"), ], ) def test_std(self, add): diff --git a/pandas/tests/dtypes/cast/test_construct_from_scalar.py b/pandas/tests/dtypes/cast/test_construct_from_scalar.py index eccd838a11331..0ce04ce2e64cd 100644 --- a/pandas/tests/dtypes/cast/test_construct_from_scalar.py +++ b/pandas/tests/dtypes/cast/test_construct_from_scalar.py @@ -7,7 +7,6 @@ from pandas import ( Categorical, Timedelta, - Timestamp, ) import pandas._testing as tm @@ -25,9 +24,9 @@ def test_cast_1d_array_like_from_scalar_categorical(): tm.assert_categorical_equal(result, expected) -def test_cast_1d_array_like_from_timestamp(): +def test_cast_1d_array_like_from_timestamp(fixed_now_ts): # check we dont lose nanoseconds - ts = Timestamp.now() + Timedelta(1) + ts = fixed_now_ts + Timedelta(1) res = construct_1d_arraylike_from_scalar(ts, 2, np.dtype("M8[ns]")) assert res[0] == ts diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 55d0e5e73418e..d05499cdb444c 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -44,8 +44,8 @@ import pandas._testing as tm from pandas.core.api import Float64Index -now = pd.Timestamp.now() -utcnow = pd.Timestamp.now("UTC") +fix_now = pd.Timestamp("2021-01-01") +fix_utcnow = pd.Timestamp("2021-01-01", tz="UTC") @pytest.mark.parametrize("notna_f", [notna, notnull]) @@ -467,12 +467,12 @@ def test_array_equivalent_different_dtype_but_equal(): # There are 3 variants for each of lvalue and rvalue. We include all # three for the tz-naive `now` and exclude the datetim64 variant # for utcnow because it drops tzinfo. - (now, utcnow), - (now.to_datetime64(), utcnow), - (now.to_pydatetime(), utcnow), - (now, utcnow), - (now.to_datetime64(), utcnow.to_pydatetime()), - (now.to_pydatetime(), utcnow.to_pydatetime()), + (fix_now, fix_utcnow), + (fix_now.to_datetime64(), fix_utcnow), + (fix_now.to_pydatetime(), fix_utcnow), + (fix_now, fix_utcnow), + (fix_now.to_datetime64(), fix_utcnow.to_pydatetime()), + (fix_now.to_pydatetime(), fix_utcnow.to_pydatetime()), ], ) def test_array_equivalent_tzawareness(lvalue, rvalue): diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 359f166b9855e..abd72d3780a05 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2888,8 +2888,8 @@ def test_from_timedelta_scalar_preserves_nanos(self, constructor): obj = constructor(td, dtype="m8[ns]") assert get1(obj) == td - def test_from_timestamp_scalar_preserves_nanos(self, constructor): - ts = Timestamp.now() + Timedelta(1) + def test_from_timestamp_scalar_preserves_nanos(self, constructor, fixed_now_ts): + ts = fixed_now_ts + Timedelta(1) obj = constructor(ts, dtype="M8[ns]") assert get1(obj) == ts diff --git a/pandas/tests/indexes/timedeltas/test_indexing.py b/pandas/tests/indexes/timedeltas/test_indexing.py index 0c2f8d0103ceb..b618f12e9f6c9 100644 --- a/pandas/tests/indexes/timedeltas/test_indexing.py +++ b/pandas/tests/indexes/timedeltas/test_indexing.py @@ -149,7 +149,7 @@ def test_where_doesnt_retain_freq(self): result = tdi.where(cond, tdi[::-1]) tm.assert_index_equal(result, expected) - def test_where_invalid_dtypes(self): + def test_where_invalid_dtypes(self, fixed_now_ts): tdi = timedelta_range("1 day", periods=3, freq="D", name="idx") tail = tdi[2:].tolist() @@ -161,17 +161,17 @@ def test_where_invalid_dtypes(self): result = tdi.where(mask, i2.asi8) tm.assert_index_equal(result, expected) - ts = i2 + Timestamp.now() + ts = i2 + fixed_now_ts expected = Index([ts[0], ts[1]] + tail, dtype=object, name="idx") result = tdi.where(mask, ts) tm.assert_index_equal(result, expected) - per = (i2 + Timestamp.now()).to_period("D") + per = (i2 + fixed_now_ts).to_period("D") expected = Index([per[0], per[1]] + tail, dtype=object, name="idx") result = tdi.where(mask, per) tm.assert_index_equal(result, expected) - ts = Timestamp.now() + ts = fixed_now_ts expected = Index([ts, ts] + tail, dtype=object, name="idx") result = tdi.where(mask, ts) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index 73227caa9fd62..f2c2985827a4f 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -645,11 +645,11 @@ def test_nat_comparisons_invalid_ndarray(other): op(other, NaT) -def test_compare_date(): +def test_compare_date(fixed_now_ts): # GH#39151 comparing NaT with date object is deprecated # See also: tests.scalar.timestamps.test_comparisons::test_compare_date - dt = Timestamp.now().to_pydatetime().date() + dt = fixed_now_ts.to_pydatetime().date() for left, right in [(NaT, dt), (dt, NaT)]: assert not left == right diff --git a/pandas/tests/scalar/timestamp/test_arithmetic.py b/pandas/tests/scalar/timestamp/test_arithmetic.py index fd46954fd4c71..1a8fd2a8199a2 100644 --- a/pandas/tests/scalar/timestamp/test_arithmetic.py +++ b/pandas/tests/scalar/timestamp/test_arithmetic.py @@ -91,7 +91,7 @@ def test_delta_preserve_nanos(self): def test_rsub_dtscalars(self, tz_naive_fixture): # In particular, check that datetime64 - Timestamp works GH#28286 td = Timedelta(1235345642000) - ts = Timestamp.now(tz_naive_fixture) + ts = Timestamp("2021-01-01", tz=tz_naive_fixture) other = ts + td assert other - ts == td @@ -170,9 +170,9 @@ def test_addition_subtraction_preserve_frequency(self, freq, td, td64): @pytest.mark.parametrize( "td", [Timedelta(hours=3), np.timedelta64(3, "h"), timedelta(hours=3)] ) - def test_radd_tdscalar(self, td): + def test_radd_tdscalar(self, td, fixed_now_ts): # GH#24775 timedelta64+Timestamp should not raise - ts = Timestamp.now() + ts = fixed_now_ts assert td + ts == ts + td @pytest.mark.parametrize( diff --git a/pandas/tests/scalar/timestamp/test_comparisons.py b/pandas/tests/scalar/timestamp/test_comparisons.py index b7cb7ca8d7069..7ed0a6aedebc1 100644 --- a/pandas/tests/scalar/timestamp/test_comparisons.py +++ b/pandas/tests/scalar/timestamp/test_comparisons.py @@ -12,8 +12,8 @@ class TestTimestampComparison: - def test_comparison_dt64_ndarray(self): - ts = Timestamp.now() + def test_comparison_dt64_ndarray(self, fixed_now_ts): + ts = Timestamp("2021-01-01") ts2 = Timestamp("2019-04-05") arr = np.array([[ts.asm8, ts2.asm8]], dtype="M8[ns]") @@ -51,7 +51,7 @@ def test_comparison_dt64_ndarray(self): @pytest.mark.parametrize("reverse", [True, False]) def test_comparison_dt64_ndarray_tzaware(self, reverse, comparison_op): - ts = Timestamp.now("UTC") + ts = Timestamp("2021-01-01 00:00:00.00000", tz="UTC") arr = np.array([ts.asm8, ts.asm8], dtype="M8[ns]") left, right = ts, arr @@ -147,7 +147,7 @@ def test_compare_invalid(self): @pytest.mark.parametrize("tz", [None, "US/Pacific"]) def test_compare_date(self, tz): # GH#36131 comparing Timestamp with date object is deprecated - ts = Timestamp.now(tz) + ts = Timestamp("2021-01-01 00:00:00.00000", tz=tz) dt = ts.to_pydatetime().date() # These are incorrectly considered as equal because they # dispatch to the date comparisons which truncates ts @@ -278,9 +278,9 @@ def test_timestamp_compare_oob_dt64(self): assert Timestamp.min > other assert other < Timestamp.min - def test_compare_zerodim_array(self): + def test_compare_zerodim_array(self, fixed_now_ts): # GH#26916 - ts = Timestamp.now() + ts = fixed_now_ts dt64 = np.datetime64("2016-01-01", "ns") arr = np.array(dt64) assert arr.ndim == 0 diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index 366c0f7cf2f74..ab114e65b2422 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -490,10 +490,10 @@ def test_normalize_pre_epoch_dates(self): # -------------------------------------------------------------- @td.skip_if_windows - def test_timestamp(self): + def test_timestamp(self, fixed_now_ts): # GH#17329 # tz-naive --> treat it as if it were UTC for purposes of timestamp() - ts = Timestamp.now() + ts = fixed_now_ts uts = ts.replace(tzinfo=utc) assert ts.timestamp() == uts.timestamp() diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 3a6cd4eb0face..8283604b99d32 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -419,10 +419,10 @@ def test_replace_empty_copy(self, frame): tm.assert_equal(res, obj) assert res is not obj - def test_replace_only_one_dictlike_arg(self): + def test_replace_only_one_dictlike_arg(self, fixed_now_ts): # GH#33340 - ser = pd.Series([1, 2, "A", pd.Timestamp.now(), True]) + ser = pd.Series([1, 2, "A", fixed_now_ts, True]) to_replace = {0: 1, 2: "A"} value = "foo" msg = "Series.replace cannot use dict-like to_replace and non-None value" diff --git a/pandas/tests/tools/test_to_timedelta.py b/pandas/tests/tools/test_to_timedelta.py index 395fdea67f1bd..7b35e8d55c338 100644 --- a/pandas/tests/tools/test_to_timedelta.py +++ b/pandas/tests/tools/test_to_timedelta.py @@ -267,9 +267,9 @@ def test_to_timedelta_precision_over_nanos(self, input, expected, func): result = func(input) assert result == expected - def test_to_timedelta_zerodim(self): + def test_to_timedelta_zerodim(self, fixed_now_ts): # ndarray.item() incorrectly returns int for dt64[ns] and td64[ns] - dt64 = pd.Timestamp.now().to_datetime64() + dt64 = fixed_now_ts.to_datetime64() arg = np.array(dt64) msg = ( diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 0c79c0b64f4cd..1b2456c6f5103 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -498,11 +498,11 @@ def test_pickle_dateoffset_odd_inputs(self): base_dt = datetime(2020, 1, 1) assert base_dt + off == base_dt + res - def test_onOffset_deprecated(self, offset_types): + def test_onOffset_deprecated(self, offset_types, fixed_now_ts): # GH#30340 use idiomatic naming off = self._get_offset(offset_types) - ts = Timestamp.now() + ts = fixed_now_ts with tm.assert_produces_warning(FutureWarning): result = off.onOffset(ts) diff --git a/pandas/tests/tslibs/test_timezones.py b/pandas/tests/tslibs/test_timezones.py index fbda5e8fda9dd..7ab0ad0856af0 100644 --- a/pandas/tests/tslibs/test_timezones.py +++ b/pandas/tests/tslibs/test_timezones.py @@ -143,7 +143,7 @@ def test_maybe_get_tz_invalid_types(): msg = "" with pytest.raises(TypeError, match=msg): - timezones.maybe_get_tz(Timestamp.now("UTC")) + timezones.maybe_get_tz(Timestamp("2021-01-01", tz="UTC")) def test_maybe_get_tz_offset_only():