@@ -201,17 +201,17 @@ class TestTimestampConstructors:
201
201
def test_constructor (self ):
202
202
base_str = "2014-07-01 09:00"
203
203
base_dt = datetime (2014 , 7 , 1 , 9 )
204
- base_expected = 1404205200000000000
204
+ base_expected = 1_404_205_200_000_000_000
205
205
206
206
# confirm base representation is correct
207
- assert calendar .timegm (base_dt .timetuple ()) * 1000000000 == base_expected
207
+ assert calendar .timegm (base_dt .timetuple ()) * 1_000_000_000 == base_expected
208
208
209
209
tests = [
210
210
(base_str , base_dt , base_expected ),
211
211
(
212
212
"2014-07-01 10:00" ,
213
213
datetime (2014 , 7 , 1 , 10 ),
214
- base_expected + 3600 * 1000000000 ,
214
+ base_expected + 3600 * 1_000_000_000 ,
215
215
),
216
216
(
217
217
"2014-07-01 09:00:00.000008000" ,
@@ -250,7 +250,7 @@ def test_constructor(self):
250
250
# with timezone
251
251
for tz , offset in timezones :
252
252
for result in [Timestamp (date_str , tz = tz ), Timestamp (date , tz = tz )]:
253
- expected_tz = expected - offset * 3600 * 1000000000
253
+ expected_tz = expected - offset * 3600 * 1_000_000_000
254
254
assert result .value == expected_tz
255
255
assert conversion .pydt_to_i8 (result ) == expected_tz
256
256
@@ -264,22 +264,22 @@ def test_constructor(self):
264
264
result = Timestamp (result ).tz_convert ("UTC" )
265
265
else :
266
266
result = Timestamp (result , tz = "UTC" )
267
- expected_utc = expected - offset * 3600 * 1000000000
267
+ expected_utc = expected - offset * 3600 * 1_000_000_000
268
268
assert result .value == expected_utc
269
269
assert conversion .pydt_to_i8 (result ) == expected_utc
270
270
271
271
def test_constructor_with_stringoffset (self ):
272
272
# GH 7833
273
273
base_str = "2014-07-01 11:00:00+02:00"
274
274
base_dt = datetime (2014 , 7 , 1 , 9 )
275
- base_expected = 1404205200000000000
275
+ base_expected = 1_404_205_200_000_000_000
276
276
277
277
# confirm base representation is correct
278
- assert calendar .timegm (base_dt .timetuple ()) * 1000000000 == base_expected
278
+ assert calendar .timegm (base_dt .timetuple ()) * 1_000_000_000 == base_expected
279
279
280
280
tests = [
281
281
(base_str , base_expected ),
282
- ("2014-07-01 12:00:00+02:00" , base_expected + 3600 * 1000000000 ),
282
+ ("2014-07-01 12:00:00+02:00" , base_expected + 3600 * 1_000_000_000 ),
283
283
("2014-07-01 11:00:00.000008000+02:00" , base_expected + 8000 ),
284
284
("2014-07-01 11:00:00.000000005+02:00" , base_expected + 5 ),
285
285
]
@@ -725,7 +725,7 @@ def test_utc_z_designator(self):
725
725
assert get_timezone (Timestamp ("2014-11-02 01:00Z" ).tzinfo ) is utc
726
726
727
727
def test_asm8 (self ):
728
- np .random .seed (7960929 )
728
+ np .random .seed (7_960_929 )
729
729
ns = [Timestamp .min .value , Timestamp .max .value , 1000 ]
730
730
731
731
for n in ns :
@@ -786,15 +786,15 @@ def compare(x, y):
786
786
)
787
787
788
788
def test_basics_nanos (self ):
789
- val = np .int64 (946684800000000000 ).view ("M8[ns]" )
789
+ val = np .int64 (946_684_800_000_000_000 ).view ("M8[ns]" )
790
790
stamp = Timestamp (val .view ("i8" ) + 500 )
791
791
assert stamp .year == 2000
792
792
assert stamp .month == 1
793
793
assert stamp .microsecond == 0
794
794
assert stamp .nanosecond == 500
795
795
796
796
# GH 14415
797
- val = np .iinfo (np .int64 ).min + 80000000000000
797
+ val = np .iinfo (np .int64 ).min + 80_000_000_000_000
798
798
stamp = Timestamp (val )
799
799
assert stamp .year == 1677
800
800
assert stamp .month == 9
@@ -807,8 +807,8 @@ def test_basics_nanos(self):
807
807
[
808
808
[946688461000000000 , {}],
809
809
[946688461000000000 / 1000 , dict (unit = "us" )],
810
- [946688461000000000 / 1000000 , dict (unit = "ms" )],
811
- [946688461000000000 / 1000000000 , dict (unit = "s" )],
810
+ [946688461000000000 / 1_000_000 , dict (unit = "ms" )],
811
+ [946688461000000000 / 1_000_000_000 , dict (unit = "s" )],
812
812
[10957 , dict (unit = "D" , h = 0 )],
813
813
[
814
814
(946688461000000000 + 500000 ) / 1000000000 ,
@@ -852,24 +852,24 @@ def test_roundtrip(self):
852
852
base = Timestamp ("20140101 00:00:00" )
853
853
854
854
result = Timestamp (base .value + Timedelta ("5ms" ).value )
855
- assert result == Timestamp (str ( base ) + " .005000" )
855
+ assert result == Timestamp (f" { base } .005000" )
856
856
assert result .microsecond == 5000
857
857
858
858
result = Timestamp (base .value + Timedelta ("5us" ).value )
859
- assert result == Timestamp (str ( base ) + " .000005" )
859
+ assert result == Timestamp (f" { base } .000005" )
860
860
assert result .microsecond == 5
861
861
862
862
result = Timestamp (base .value + Timedelta ("5ns" ).value )
863
- assert result == Timestamp (str ( base ) + " .000000005" )
863
+ assert result == Timestamp (f" { base } .000000005" )
864
864
assert result .nanosecond == 5
865
865
assert result .microsecond == 0
866
866
867
867
result = Timestamp (base .value + Timedelta ("6ms 5us" ).value )
868
- assert result == Timestamp (str ( base ) + " .006005" )
868
+ assert result == Timestamp (f" { base } .006005" )
869
869
assert result .microsecond == 5 + 6 * 1000
870
870
871
871
result = Timestamp (base .value + Timedelta ("200ms 5us" ).value )
872
- assert result == Timestamp (str ( base ) + " .200005" )
872
+ assert result == Timestamp (f" { base } .200005" )
873
873
assert result .microsecond == 5 + 200 * 1000
874
874
875
875
def test_hash_equivalent (self ):
@@ -890,20 +890,20 @@ def test_nanosecond_string_parsing(self):
890
890
ts = Timestamp ("2013-05-01 07:15:45.123456789" )
891
891
# GH 7878
892
892
expected_repr = "2013-05-01 07:15:45.123456789"
893
- expected_value = 1367392545123456789
893
+ expected_value = 1_367_392_545_123_456_789
894
894
assert ts .value == expected_value
895
895
assert expected_repr in repr (ts )
896
896
897
897
ts = Timestamp ("2013-05-01 07:15:45.123456789+09:00" , tz = "Asia/Tokyo" )
898
- assert ts .value == expected_value - 9 * 3600 * 1000000000
898
+ assert ts .value == expected_value - 9 * 3600 * 1_000_000_000
899
899
assert expected_repr in repr (ts )
900
900
901
901
ts = Timestamp ("2013-05-01 07:15:45.123456789" , tz = "UTC" )
902
902
assert ts .value == expected_value
903
903
assert expected_repr in repr (ts )
904
904
905
905
ts = Timestamp ("2013-05-01 07:15:45.123456789" , tz = "US/Eastern" )
906
- assert ts .value == expected_value + 4 * 3600 * 1000000000
906
+ assert ts .value == expected_value + 4 * 3600 * 1_000_000_000
907
907
assert expected_repr in repr (ts )
908
908
909
909
# GH 10041
@@ -913,7 +913,7 @@ def test_nanosecond_string_parsing(self):
913
913
914
914
def test_nanosecond_timestamp (self ):
915
915
# GH 7610
916
- expected = 1293840000000000005
916
+ expected = 1_293_840_000_000_000_005
917
917
t = Timestamp ("2011-01-01" ) + offsets .Nano (5 )
918
918
assert repr (t ) == "Timestamp('2011-01-01 00:00:00.000000005')"
919
919
assert t .value == expected
@@ -929,7 +929,7 @@ def test_nanosecond_timestamp(self):
929
929
assert t .value == expected
930
930
assert t .nanosecond == 5
931
931
932
- expected = 1293840000000000010
932
+ expected = 1_293_840_000_000_000_010
933
933
t = t + offsets .Nano (5 )
934
934
assert repr (t ) == "Timestamp('2011-01-01 00:00:00.000000010')"
935
935
assert t .value == expected
@@ -949,23 +949,23 @@ def test_nanosecond_timestamp(self):
949
949
class TestTimestampToJulianDate :
950
950
def test_compare_1700 (self ):
951
951
r = Timestamp ("1700-06-23" ).to_julian_date ()
952
- assert r == 2342145 .5
952
+ assert r == 2_342_145 .5
953
953
954
954
def test_compare_2000 (self ):
955
955
r = Timestamp ("2000-04-12" ).to_julian_date ()
956
- assert r == 2451646 .5
956
+ assert r == 2_451_646 .5
957
957
958
958
def test_compare_2100 (self ):
959
959
r = Timestamp ("2100-08-12" ).to_julian_date ()
960
- assert r == 2488292 .5
960
+ assert r == 2_488_292 .5
961
961
962
962
def test_compare_hour01 (self ):
963
963
r = Timestamp ("2000-08-12T01:00:00" ).to_julian_date ()
964
- assert r == 2451768 .5416666666666666
964
+ assert r == 2_451_768 .5416666666666666
965
965
966
966
def test_compare_hour13 (self ):
967
967
r = Timestamp ("2000-08-12T13:00:00" ).to_julian_date ()
968
- assert r == 2451769 .0416666666666666
968
+ assert r == 2_451_769 .0416666666666666
969
969
970
970
971
971
class TestTimestampConversion :
0 commit comments