Skip to content

Commit d4a5536

Browse files
update tests
1 parent fcb2953 commit d4a5536

12 files changed

+42
-58
lines changed

pandas/tests/io/parser/common/test_common_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_read_csv_local(all_parsers, csv1):
6565
datetime(2000, 1, 10),
6666
datetime(2000, 1, 11),
6767
],
68-
dtype="M8[s]",
68+
dtype="M8[us]" if all_parsers.engine != "pyarrow" else "M8[s]",
6969
name="index",
7070
),
7171
)
@@ -167,7 +167,7 @@ def test_read_csv_dataframe(all_parsers, csv1):
167167
datetime(2000, 1, 10),
168168
datetime(2000, 1, 11),
169169
],
170-
dtype="M8[s]",
170+
dtype="M8[us]" if all_parsers.engine != "pyarrow" else "M8[s]",
171171
name="index",
172172
),
173173
)

pandas/tests/io/parser/common/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def test_read_csv_no_index_name(all_parsers, csv_dir_path):
263263
datetime(2000, 1, 6),
264264
datetime(2000, 1, 7),
265265
],
266-
dtype="M8[s]",
266+
dtype="M8[us]",
267267
),
268268
)
269269
tm.assert_frame_equal(result, expected)

pandas/tests/io/parser/test_multi_thread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,5 @@ def test_multi_thread_path_multipart_read_csv(all_parsers):
155155
result = _generate_multi_thread_dataframe(parser, path, num_rows, num_tasks)
156156

157157
expected = df[:]
158-
expected["date"] = expected["date"].astype("M8[s]")
158+
expected["date"] = expected["date"].astype("M8[us]")
159159
tm.assert_frame_equal(result, expected)

pandas/tests/io/parser/test_parse_dates.py

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def test_date_col_as_index_col(all_parsers):
6161
datetime(1999, 1, 27, 21, 0),
6262
datetime(1999, 1, 27, 22, 0),
6363
],
64-
dtype="M8[s]",
6564
name="X1",
6665
)
6766
expected = DataFrame(
@@ -126,7 +125,7 @@ def test_parse_dates_string(all_parsers):
126125
parser = all_parsers
127126
result = parser.read_csv(StringIO(data), index_col="date", parse_dates=["date"])
128127
# 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)
130129

131130
expected = DataFrame(
132131
{"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):
143142
expected = DataFrame(
144143
{"a": [datetime(2010, 1, 1)], "b": [1], "c": [datetime(2010, 2, 15)]}
145144
)
146-
expected["a"] = expected["a"].astype("M8[s]")
147-
expected["c"] = expected["c"].astype("M8[s]")
148145
expected = expected.set_index(["a", "b"])
149146

150147
result = parser.read_csv(
@@ -168,7 +165,7 @@ def test_multi_index_parse_dates(all_parsers, index_col):
168165
20090103,three,c,4,5
169166
"""
170167
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")
172169
index = MultiIndex.from_product(
173170
[
174171
dti,
@@ -218,6 +215,7 @@ def test_parse_tz_aware(all_parsers):
218215
if parser.engine == "pyarrow":
219216
pytz = pytest.importorskip("pytz")
220217
expected_tz = pytz.utc
218+
expected.index = expected.index.as_unit("s")
221219
else:
222220
expected_tz = timezone.utc
223221
tm.assert_frame_equal(result, expected)
@@ -303,7 +301,7 @@ def test_parse_dates_empty_string(all_parsers):
303301
expected = DataFrame(
304302
[[datetime(2012, 1, 1), 1], [pd.NaT, 2]], columns=["Date", "test"]
305303
)
306-
expected["Date"] = expected["Date"].astype("M8[s]")
304+
expected["Date"] = expected["Date"].astype("M8[us]")
307305
tm.assert_frame_equal(result, expected)
308306

309307

@@ -314,22 +312,18 @@ def test_parse_dates_empty_string(all_parsers):
314312
(
315313
"a\n04.15.2016",
316314
{"parse_dates": ["a"]},
317-
DataFrame([datetime(2016, 4, 15)], columns=["a"], dtype="M8[s]"),
315+
DataFrame([datetime(2016, 4, 15)], columns=["a"]),
318316
),
319317
(
320318
"a\n04.15.2016",
321319
{"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=[]),
325321
),
326322
(
327323
"a,b\n04.15.2016,09.16.2013",
328324
{"parse_dates": ["a", "b"]},
329325
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"]
333327
),
334328
),
335329
(
@@ -339,8 +333,8 @@ def test_parse_dates_empty_string(all_parsers):
339333
index=MultiIndex.from_tuples(
340334
[
341335
(
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),
344338
)
345339
],
346340
names=["a", "b"],
@@ -411,7 +405,7 @@ def test_parse_timezone(all_parsers):
411405
end="2018-01-04 09:05:00",
412406
freq="1min",
413407
tz=timezone(timedelta(minutes=540)),
414-
unit="s",
408+
unit="us",
415409
)._with_freq(None)
416410
expected_data = {"dt": dti, "val": [23350, 23400, 23400, 23400, 23400]}
417411

@@ -450,7 +444,7 @@ def test_parse_delimited_date_swap_no_warning(
450444
all_parsers, date_string, dayfirst, expected, request
451445
):
452446
parser = all_parsers
453-
expected = DataFrame({0: [expected]}, dtype="datetime64[s]")
447+
expected = DataFrame({0: [expected]}, dtype="datetime64[us]")
454448
if parser.engine == "pyarrow":
455449
if not dayfirst:
456450
# "CSV parse error: Empty CSV file or block"
@@ -483,7 +477,7 @@ def test_parse_delimited_date_swap_with_warning(
483477
all_parsers, date_string, dayfirst, expected
484478
):
485479
parser = all_parsers
486-
expected = DataFrame({0: [expected]}, dtype="datetime64[s]")
480+
expected = DataFrame({0: [expected]}, dtype="datetime64[us]")
487481
warning_msg = (
488482
"Parsing dates in .* format when dayfirst=.* was specified. "
489483
"Pass `dayfirst=.*` or specify a format to silence this warning."
@@ -602,7 +596,6 @@ def test_date_parser_usecols_thousands(all_parsers):
602596
thousands="-",
603597
)
604598
expected = DataFrame({"B": [3, 4], "C": [Timestamp("20-09-2001 01:00:00")] * 2})
605-
expected["C"] = expected["C"].astype("M8[s]")
606599
tm.assert_frame_equal(result, expected)
607600

608601

@@ -611,9 +604,7 @@ def test_dayfirst_warnings():
611604

612605
# CASE 1: valid input
613606
input = "date\n31/12/2014\n10/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")
617608
warning_msg = (
618609
"Parsing dates in .* format when dayfirst=.* was specified. "
619610
"Pass `dayfirst=.*` or specify a format to silence this warning."
@@ -672,9 +663,7 @@ def test_dayfirst_warnings():
672663
def test_dayfirst_warnings_no_leading_zero(date_string, dayfirst):
673664
# GH47880
674665
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")
678667
warning_msg = (
679668
"Parsing dates in .* format when dayfirst=.* was specified. "
680669
"Pass `dayfirst=.*` or specify a format to silence this warning."
@@ -729,7 +718,7 @@ def test_replace_nans_before_parsing_dates(all_parsers):
729718
Timestamp("2017-09-09"),
730719
]
731720
},
732-
dtype="M8[s]",
721+
dtype="M8[us]",
733722
)
734723
tm.assert_frame_equal(result, expected)
735724

@@ -744,7 +733,6 @@ def test_parse_dates_and_string_dtype(all_parsers):
744733
result = parser.read_csv(StringIO(data), dtype="string", parse_dates=["b"])
745734
expected = DataFrame({"a": ["1"], "b": [Timestamp("2019-12-31")]})
746735
expected["a"] = expected["a"].astype("string")
747-
expected["b"] = expected["b"].astype("M8[s]")
748736
tm.assert_frame_equal(result, expected)
749737

750738

@@ -763,9 +751,7 @@ def test_parse_dot_separated_dates(all_parsers):
763751
warn = None
764752
else:
765753
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"
769755
)
770756
warn = UserWarning
771757
msg = r"when dayfirst=False \(the default\) was specified"
@@ -798,7 +784,7 @@ def test_parse_dates_dict_format(all_parsers):
798784
"a": [Timestamp("2019-12-31"), Timestamp("2020-12-31")],
799785
"b": [Timestamp("2019-12-31"), Timestamp("2020-12-31")],
800786
},
801-
dtype="M8[s]",
787+
dtype="M8[us]",
802788
)
803789
tm.assert_frame_equal(result, expected)
804790

@@ -840,6 +826,8 @@ def test_parse_dates_arrow_engine(all_parsers):
840826
"b": 1,
841827
}
842828
)
829+
if parser.engine == "pyarrow":
830+
expected["a"] = expected["a"].dt.as_unit("s")
843831
tm.assert_frame_equal(result, expected)
844832

845833

pandas/tests/io/parser/test_read_fwf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ def test_fwf_regression():
308308
parse_dates=True,
309309
date_format="%Y%j%H%M%S",
310310
)
311-
expected.index = expected.index.astype("M8[s]")
312311
tm.assert_frame_equal(result, expected)
313312

314313

pandas/tests/io/parser/test_skiprows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_skip_rows_bug(all_parsers, skiprows):
4343
)
4444
index = Index(
4545
[datetime(2000, 1, 1), datetime(2000, 1, 2), datetime(2000, 1, 3)],
46-
dtype="M8[s]",
46+
dtype="M8[us]",
4747
name=0,
4848
)
4949

@@ -88,7 +88,7 @@ def test_skip_rows_blank(all_parsers):
8888
)
8989
index = Index(
9090
[datetime(2000, 1, 1), datetime(2000, 1, 2), datetime(2000, 1, 3)],
91-
dtype="M8[s]",
91+
dtype="M8[us]",
9292
name=0,
9393
)
9494

pandas/tests/io/pytables/test_append.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def test_append_raise(setup_path, using_infer_string):
826826
msg = re.escape(
827827
"Cannot serialize the column [foo] "
828828
"because its data contents are not [string] "
829-
"but [datetime64[s]] object dtype"
829+
"but [datetime64[us]] object dtype"
830830
)
831831
with pytest.raises(ValueError, match=msg):
832832
store.append("df", df)

pandas/tests/io/pytables/test_round_trip.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ def test_table_values_dtypes_roundtrip(setup_path, using_infer_string):
252252
"int8": 1,
253253
"int64": 1,
254254
str_dtype: 1,
255-
"datetime64[s]": 2,
256-
"datetime64[ms]": 1,
255+
"datetime64[us]": 3,
257256
"datetime64[ns]": 1,
258257
},
259258
name="count",

pandas/tests/io/test_gcs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ def from_uri(path):
117117
df2 = df1
118118

119119
expected = df1[:]
120-
if format in ["csv", "excel"]:
121-
expected["dt"] = expected["dt"].dt.as_unit("s")
122120

123121
tm.assert_frame_equal(df2, expected)
124122

pandas/tests/io/test_sql.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,10 +1858,8 @@ def test_api_custom_dateparsing_error(
18581858

18591859
if conn_name == "postgresql_adbc_types" and pa_version_under14p1:
18601860
expected["DateCol"] = expected["DateCol"].astype("datetime64[ns]")
1861-
elif "postgres" in conn_name or "mysql" in conn_name:
1862-
expected["DateCol"] = expected["DateCol"].astype("datetime64[us]")
18631861
else:
1864-
expected["DateCol"] = expected["DateCol"].astype("datetime64[s]")
1862+
expected["DateCol"] = expected["DateCol"].astype("datetime64[us]")
18651863
tm.assert_frame_equal(result, expected)
18661864

18671865

0 commit comments

Comments
 (0)