@@ -61,7 +61,6 @@ def test_date_col_as_index_col(all_parsers):
61
61
datetime (1999 , 1 , 27 , 21 , 0 ),
62
62
datetime (1999 , 1 , 27 , 22 , 0 ),
63
63
],
64
- dtype = "M8[s]" ,
65
64
name = "X1" ,
66
65
)
67
66
expected = DataFrame (
@@ -126,7 +125,7 @@ def test_parse_dates_string(all_parsers):
126
125
parser = all_parsers
127
126
result = parser .read_csv (StringIO (data ), index_col = "date" , parse_dates = ["date" ])
128
127
# freq doesn't round-trip
129
- index = date_range ("1/1/2009" , periods = 3 , name = "date" , unit = "s " )._with_freq (None )
128
+ index = date_range ("1/1/2009" , periods = 3 , name = "date" , unit = "us " )._with_freq (None )
130
129
131
130
expected = DataFrame (
132
131
{"A" : ["a" , "b" , "c" ], "B" : [1 , 3 , 4 ], "C" : [2 , 4 , 5 ]}, index = index
@@ -143,8 +142,6 @@ def test_parse_dates_column_list(all_parsers, parse_dates):
143
142
expected = DataFrame (
144
143
{"a" : [datetime (2010 , 1 , 1 )], "b" : [1 ], "c" : [datetime (2010 , 2 , 15 )]}
145
144
)
146
- expected ["a" ] = expected ["a" ].astype ("M8[s]" )
147
- expected ["c" ] = expected ["c" ].astype ("M8[s]" )
148
145
expected = expected .set_index (["a" , "b" ])
149
146
150
147
result = parser .read_csv (
@@ -168,7 +165,7 @@ def test_multi_index_parse_dates(all_parsers, index_col):
168
165
20090103,three,c,4,5
169
166
"""
170
167
parser = all_parsers
171
- dti = date_range ("2009-01-01" , periods = 3 , freq = "D" , unit = "s " )
168
+ dti = date_range ("2009-01-01" , periods = 3 , freq = "D" , unit = "us " )
172
169
index = MultiIndex .from_product (
173
170
[
174
171
dti ,
@@ -218,6 +215,7 @@ def test_parse_tz_aware(all_parsers):
218
215
if parser .engine == "pyarrow" :
219
216
pytz = pytest .importorskip ("pytz" )
220
217
expected_tz = pytz .utc
218
+ expected .index = expected .index .as_unit ("s" )
221
219
else :
222
220
expected_tz = timezone .utc
223
221
tm .assert_frame_equal (result , expected )
@@ -303,7 +301,7 @@ def test_parse_dates_empty_string(all_parsers):
303
301
expected = DataFrame (
304
302
[[datetime (2012 , 1 , 1 ), 1 ], [pd .NaT , 2 ]], columns = ["Date" , "test" ]
305
303
)
306
- expected ["Date" ] = expected ["Date" ].astype ("M8[s ]" )
304
+ expected ["Date" ] = expected ["Date" ].astype ("M8[us ]" )
307
305
tm .assert_frame_equal (result , expected )
308
306
309
307
@@ -314,22 +312,18 @@ def test_parse_dates_empty_string(all_parsers):
314
312
(
315
313
"a\n 04.15.2016" ,
316
314
{"parse_dates" : ["a" ]},
317
- DataFrame ([datetime (2016 , 4 , 15 )], columns = ["a" ], dtype = "M8[s]" ),
315
+ DataFrame ([datetime (2016 , 4 , 15 )], columns = ["a" ]),
318
316
),
319
317
(
320
318
"a\n 04.15.2016" ,
321
319
{"parse_dates" : True , "index_col" : 0 },
322
- DataFrame (
323
- index = DatetimeIndex (["2016-04-15" ], dtype = "M8[s]" , name = "a" ), columns = []
324
- ),
320
+ DataFrame (index = DatetimeIndex (["2016-04-15" ], name = "a" ), columns = []),
325
321
),
326
322
(
327
323
"a,b\n 04.15.2016,09.16.2013" ,
328
324
{"parse_dates" : ["a" , "b" ]},
329
325
DataFrame (
330
- [[datetime (2016 , 4 , 15 ), datetime (2013 , 9 , 16 )]],
331
- dtype = "M8[s]" ,
332
- columns = ["a" , "b" ],
326
+ [[datetime (2016 , 4 , 15 ), datetime (2013 , 9 , 16 )]], columns = ["a" , "b" ]
333
327
),
334
328
),
335
329
(
@@ -339,8 +333,8 @@ def test_parse_dates_empty_string(all_parsers):
339
333
index = MultiIndex .from_tuples (
340
334
[
341
335
(
342
- Timestamp (2016 , 4 , 15 ). as_unit ( "s" ) ,
343
- Timestamp (2013 , 9 , 16 ). as_unit ( "s" ) ,
336
+ Timestamp (2016 , 4 , 15 ),
337
+ Timestamp (2013 , 9 , 16 ),
344
338
)
345
339
],
346
340
names = ["a" , "b" ],
@@ -411,7 +405,7 @@ def test_parse_timezone(all_parsers):
411
405
end = "2018-01-04 09:05:00" ,
412
406
freq = "1min" ,
413
407
tz = timezone (timedelta (minutes = 540 )),
414
- unit = "s " ,
408
+ unit = "us " ,
415
409
)._with_freq (None )
416
410
expected_data = {"dt" : dti , "val" : [23350 , 23400 , 23400 , 23400 , 23400 ]}
417
411
@@ -450,7 +444,7 @@ def test_parse_delimited_date_swap_no_warning(
450
444
all_parsers , date_string , dayfirst , expected , request
451
445
):
452
446
parser = all_parsers
453
- expected = DataFrame ({0 : [expected ]}, dtype = "datetime64[s ]" )
447
+ expected = DataFrame ({0 : [expected ]}, dtype = "datetime64[us ]" )
454
448
if parser .engine == "pyarrow" :
455
449
if not dayfirst :
456
450
# "CSV parse error: Empty CSV file or block"
@@ -483,7 +477,7 @@ def test_parse_delimited_date_swap_with_warning(
483
477
all_parsers , date_string , dayfirst , expected
484
478
):
485
479
parser = all_parsers
486
- expected = DataFrame ({0 : [expected ]}, dtype = "datetime64[s ]" )
480
+ expected = DataFrame ({0 : [expected ]}, dtype = "datetime64[us ]" )
487
481
warning_msg = (
488
482
"Parsing dates in .* format when dayfirst=.* was specified. "
489
483
"Pass `dayfirst=.*` or specify a format to silence this warning."
@@ -602,7 +596,6 @@ def test_date_parser_usecols_thousands(all_parsers):
602
596
thousands = "-" ,
603
597
)
604
598
expected = DataFrame ({"B" : [3 , 4 ], "C" : [Timestamp ("20-09-2001 01:00:00" )] * 2 })
605
- expected ["C" ] = expected ["C" ].astype ("M8[s]" )
606
599
tm .assert_frame_equal (result , expected )
607
600
608
601
@@ -611,9 +604,7 @@ def test_dayfirst_warnings():
611
604
612
605
# CASE 1: valid input
613
606
input = "date\n 31/12/2014\n 10/03/2011"
614
- expected = DatetimeIndex (
615
- ["2014-12-31" , "2011-03-10" ], dtype = "datetime64[s]" , freq = None , name = "date"
616
- )
607
+ expected = DatetimeIndex (["2014-12-31" , "2011-03-10" ], freq = None , name = "date" )
617
608
warning_msg = (
618
609
"Parsing dates in .* format when dayfirst=.* was specified. "
619
610
"Pass `dayfirst=.*` or specify a format to silence this warning."
@@ -672,9 +663,7 @@ def test_dayfirst_warnings():
672
663
def test_dayfirst_warnings_no_leading_zero (date_string , dayfirst ):
673
664
# GH47880
674
665
initial_value = f"date\n { date_string } "
675
- expected = DatetimeIndex (
676
- ["2014-01-31" ], dtype = "datetime64[s]" , freq = None , name = "date"
677
- )
666
+ expected = DatetimeIndex (["2014-01-31" ], freq = None , name = "date" )
678
667
warning_msg = (
679
668
"Parsing dates in .* format when dayfirst=.* was specified. "
680
669
"Pass `dayfirst=.*` or specify a format to silence this warning."
@@ -729,7 +718,7 @@ def test_replace_nans_before_parsing_dates(all_parsers):
729
718
Timestamp ("2017-09-09" ),
730
719
]
731
720
},
732
- dtype = "M8[s ]" ,
721
+ dtype = "M8[us ]" ,
733
722
)
734
723
tm .assert_frame_equal (result , expected )
735
724
@@ -744,7 +733,6 @@ def test_parse_dates_and_string_dtype(all_parsers):
744
733
result = parser .read_csv (StringIO (data ), dtype = "string" , parse_dates = ["b" ])
745
734
expected = DataFrame ({"a" : ["1" ], "b" : [Timestamp ("2019-12-31" )]})
746
735
expected ["a" ] = expected ["a" ].astype ("string" )
747
- expected ["b" ] = expected ["b" ].astype ("M8[s]" )
748
736
tm .assert_frame_equal (result , expected )
749
737
750
738
@@ -763,9 +751,7 @@ def test_parse_dot_separated_dates(all_parsers):
763
751
warn = None
764
752
else :
765
753
expected_index = DatetimeIndex (
766
- ["2003-03-27 14:55:00" , "2003-08-03 15:20:00" ],
767
- dtype = "datetime64[ms]" ,
768
- name = "a" ,
754
+ ["2003-03-27 14:55:00" , "2003-08-03 15:20:00" ], name = "a"
769
755
)
770
756
warn = UserWarning
771
757
msg = r"when dayfirst=False \(the default\) was specified"
@@ -798,7 +784,7 @@ def test_parse_dates_dict_format(all_parsers):
798
784
"a" : [Timestamp ("2019-12-31" ), Timestamp ("2020-12-31" )],
799
785
"b" : [Timestamp ("2019-12-31" ), Timestamp ("2020-12-31" )],
800
786
},
801
- dtype = "M8[s ]" ,
787
+ dtype = "M8[us ]" ,
802
788
)
803
789
tm .assert_frame_equal (result , expected )
804
790
@@ -840,6 +826,8 @@ def test_parse_dates_arrow_engine(all_parsers):
840
826
"b" : 1 ,
841
827
}
842
828
)
829
+ if parser .engine == "pyarrow" :
830
+ expected ["a" ] = expected ["a" ].dt .as_unit ("s" )
843
831
tm .assert_frame_equal (result , expected )
844
832
845
833
0 commit comments