@@ -168,7 +168,7 @@ def test_take(self):
168
168
169
169
tm .assert_index_equal (self .index_cls (result ), expected )
170
170
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 ])
172
172
def test_take_fill_raises (self , fill_value ):
173
173
data = np .arange (10 , dtype = "i8" ) * 24 * 3600 * 10 ** 9
174
174
@@ -842,26 +842,27 @@ def test_int_properties(self, arr1d, propname):
842
842
def test_take_fill_valid (self , arr1d ):
843
843
arr = arr1d
844
844
dti = self .index_cls (arr1d )
845
+ dt_ind = Timestamp (2021 , 1 , 1 , 12 )
846
+ dt_ind_tz = dt_ind .tz_localize (dti .tz )
845
847
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
849
850
850
851
msg = f"value should be a '{ arr1d ._scalar_type .__name__ } ' or 'NaT'. Got"
851
852
with pytest .raises (TypeError , match = msg ):
852
853
# 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 )
854
855
855
856
with pytest .raises (TypeError , match = msg ):
856
857
# fill_value Period invalid
857
858
arr .take ([- 1 , 1 ], allow_fill = True , fill_value = Period ("2014Q1" ))
858
859
859
860
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 )
861
862
msg = "Cannot compare tz-naive and tz-aware datetime-like objects"
862
863
with pytest .raises (TypeError , match = msg ):
863
864
# 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 )
865
866
866
867
value = NaT .value
867
868
msg = f"value should be a '{ arr1d ._scalar_type .__name__ } ' or 'NaT'. Got"
@@ -877,7 +878,7 @@ def test_take_fill_valid(self, arr1d):
877
878
if arr .tz is not None :
878
879
# GH#37356
879
880
# 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" )
881
882
msg = "Timezones don't match. .* != 'Australia/Melbourne'"
882
883
with pytest .raises (ValueError , match = msg ):
883
884
# require tz match, not just tzawareness match
@@ -1039,14 +1040,14 @@ def test_take_fill_valid(self, timedelta_index):
1039
1040
result = arr .take ([- 1 , 1 ], allow_fill = True , fill_value = td1 )
1040
1041
assert result [0 ] == td1
1041
1042
1042
- now = Timestamp . now ( )
1043
- value = now
1043
+ dt_ind = Timestamp ( 2021 , 1 , 1 , 12 )
1044
+ value = dt_ind
1044
1045
msg = f"value should be a '{ arr ._scalar_type .__name__ } ' or 'NaT'. Got"
1045
1046
with pytest .raises (TypeError , match = msg ):
1046
1047
# fill_value Timestamp invalid
1047
1048
arr .take ([0 , 1 ], allow_fill = True , fill_value = value )
1048
1049
1049
- value = now .to_period ("D" )
1050
+ value = dt_ind .to_period ("D" )
1050
1051
with pytest .raises (TypeError , match = msg ):
1051
1052
# fill_value Period invalid
1052
1053
arr .take ([0 , 1 ], allow_fill = True , fill_value = value )
0 commit comments