Skip to content

Commit 31bbee1

Browse files
committed
update tests
1 parent c2c37fc commit 31bbee1

32 files changed

+138
-135
lines changed

pandas/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def rand_series_with_duplicate_datetimeindex() -> Series:
936936
(Period("2012-01", freq="M"), "period[M]"),
937937
(Period("2012-02-01", freq="D"), "period[D]"),
938938
(
939-
Timestamp("2011-01-01", tz="US/Eastern"),
939+
Timestamp("2011-01-01", tz="US/Eastern").as_unit("s"),
940940
DatetimeTZDtype(unit="s", tz="US/Eastern"),
941941
),
942942
(Timedelta(seconds=500), "timedelta64[ns]"),

pandas/tests/arrays/test_array.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_dt64_array(dtype_unit):
127127
(
128128
pd.DatetimeIndex(["2000", "2001"]),
129129
None,
130-
DatetimeArray._from_sequence(["2000", "2001"], dtype="M8[s]"),
130+
DatetimeArray._from_sequence(["2000", "2001"], dtype="M8[us]"),
131131
),
132132
(
133133
["2000", "2001"],
@@ -323,7 +323,7 @@ def test_array_copy():
323323
([pd.Interval(0, 1), pd.Interval(1, 2)], IntervalArray.from_breaks([0, 1, 2])),
324324
# datetime
325325
(
326-
[pd.Timestamp("2000"), pd.Timestamp("2001")],
326+
[pd.Timestamp("2000").as_unit("s"), pd.Timestamp("2001").as_unit("s")],
327327
DatetimeArray._from_sequence(["2000", "2001"], dtype="M8[s]"),
328328
),
329329
(
@@ -342,7 +342,10 @@ def test_array_copy():
342342
),
343343
# datetimetz
344344
(
345-
[pd.Timestamp("2000", tz="CET"), pd.Timestamp("2001", tz="CET")],
345+
[
346+
pd.Timestamp("2000", tz="CET").as_unit("s"),
347+
pd.Timestamp("2001", tz="CET").as_unit("s"),
348+
],
346349
DatetimeArray._from_sequence(
347350
["2000", "2001"], dtype=pd.DatetimeTZDtype(tz="CET", unit="s")
348351
),

pandas/tests/extension/test_arrow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,9 +3470,9 @@ def test_string_to_datetime_parsing_cast():
34703470
# GH 56266
34713471
string_dates = ["2020-01-01 04:30:00", "2020-01-02 00:00:00", "2020-01-03 00:00:00"]
34723472
result = pd.Series(string_dates, dtype="timestamp[s][pyarrow]")
3473-
expected = pd.Series(
3474-
ArrowExtensionArray(pa.array(pd.to_datetime(string_dates), from_pandas=True))
3475-
)
3473+
3474+
pd_res = pd.to_datetime(string_dates).as_unit("s")
3475+
expected = pd.Series(ArrowExtensionArray(pa.array(pd_res, from_pandas=True)))
34763476
tm.assert_series_equal(result, expected)
34773477

34783478

pandas/tests/frame/methods/test_get_numeric_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_get_numeric_data(self, using_infer_string):
2525
objectname = np.dtype(np.object_).name
2626

2727
df = DataFrame(
28-
{"a": 1.0, "b": 2, "c": "foo", "f": Timestamp("20010102")},
28+
{"a": 1.0, "b": 2, "c": "foo", "f": Timestamp("20010102").as_unit("s")},
2929
index=np.arange(10),
3030
)
3131
result = df.dtypes

pandas/tests/frame/methods/test_to_csv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_to_csv_from_csv1_datetime(self, temp_file, datetime_frame):
5050
datetime_frame.to_csv(path)
5151
recons = self.read_csv(path, parse_dates=True)
5252
expected = datetime_frame.copy()
53-
expected.index = expected.index.as_unit("s")
53+
expected.index = expected.index.as_unit("us")
5454
tm.assert_frame_equal(expected, recons)
5555

5656
datetime_frame.to_csv(path, index_label="index")
@@ -240,8 +240,8 @@ def make_dtnat_arr(n, nnat=None):
240240
result = self.read_csv(path).apply(to_datetime)
241241

242242
expected = df[:]
243-
expected["a"] = expected["a"].astype("M8[s]")
244-
expected["b"] = expected["b"].astype("M8[s]")
243+
expected["a"] = expected["a"].astype("M8[us]")
244+
expected["b"] = expected["b"].astype("M8[us]")
245245
tm.assert_frame_equal(result, expected, check_names=False)
246246

247247
def _return_result_expected(
@@ -585,7 +585,7 @@ def test_to_csv_multiindex(self, temp_file, float_frame, datetime_frame):
585585

586586
# TODO to_csv drops column name
587587
expected = tsframe.copy()
588-
expected.index = MultiIndex.from_arrays([old_index.as_unit("s"), new_index[1]])
588+
expected.index = MultiIndex.from_arrays([old_index.as_unit("us"), new_index[1]])
589589
tm.assert_frame_equal(recons, expected, check_names=False)
590590

591591
# do not load index

pandas/tests/frame/methods/test_to_numpy.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ def test_to_numpy_datetime_with_na(self):
5555

5656
df = DataFrame(
5757
{
58-
"a": [Timestamp("1970-01-01"), Timestamp("1970-01-02"), NaT],
58+
"a": [
59+
Timestamp("1970-01-01").as_unit("s"),
60+
Timestamp("1970-01-02").as_unit("s"),
61+
NaT,
62+
],
5963
"b": [
60-
Timestamp("1970-01-01"),
64+
Timestamp("1970-01-01").as_unit("s"),
6165
np.nan,
62-
Timestamp("1970-01-02"),
66+
Timestamp("1970-01-02").as_unit("s"),
6367
],
6468
"c": [
6569
1,

pandas/tests/frame/test_block_internals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_construction_with_conversions(self):
194194

195195
expected = DataFrame(
196196
{
197-
"dt1": Timestamp("20130101"),
197+
"dt1": Timestamp("20130101").as_unit("s"),
198198
"dt2": date_range("20130101", periods=3).astype("M8[s]"),
199199
# 'dt3' : date_range('20130101 00:00:01',periods=3,freq='s'),
200200
# FIXME: don't leave commented-out

pandas/tests/frame/test_constructors.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,10 @@ def create_data(constructor):
879879
)
880880

881881
result_datetime64 = DataFrame(data_datetime64)
882+
assert result_datetime64.index.unit == "s"
883+
result_datetime64.index = result_datetime64.index.as_unit("us")
882884
result_datetime = DataFrame(data_datetime)
883885
assert result_datetime.index.unit == "us"
884-
result_datetime.index = result_datetime.index.as_unit("s")
885886
result_Timestamp = DataFrame(data_Timestamp)
886887
tm.assert_frame_equal(result_datetime64, expected)
887888
tm.assert_frame_equal(result_datetime, expected)
@@ -944,7 +945,7 @@ def test_constructor_dict_extension_scalar(self, ea_scalar_and_dtype):
944945
(Period("2020-01"), PeriodDtype("M")),
945946
(Interval(left=0, right=5), IntervalDtype("int64", "right")),
946947
(
947-
Timestamp("2011-01-01", tz="US/Eastern"),
948+
Timestamp("2011-01-01", tz="US/Eastern").as_unit("s"),
948949
DatetimeTZDtype(unit="s", tz="US/Eastern"),
949950
),
950951
],
@@ -1849,7 +1850,7 @@ def test_constructor_with_datetimes(self, using_infer_string):
18491850
"A": 1,
18501851
"B": "foo",
18511852
"C": "bar",
1852-
"D": Timestamp("20010101"),
1853+
"D": Timestamp("20010101").as_unit("s"),
18531854
"E": datetime(2001, 1, 2, 0, 0),
18541855
},
18551856
index=np.arange(10),
@@ -3076,9 +3077,9 @@ def test_from_tzaware_mixed_object_array(self):
30763077
res = DataFrame(arr, columns=["A", "B", "C"])
30773078

30783079
expected_dtypes = [
3079-
"datetime64[s]",
3080-
"datetime64[s, US/Eastern]",
3081-
"datetime64[s, CET]",
3080+
"datetime64[us]",
3081+
"datetime64[us, US/Eastern]",
3082+
"datetime64[us, CET]",
30823083
]
30833084
assert (res.dtypes == expected_dtypes).all()
30843085

pandas/tests/groupby/test_timegrouper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def test_groupby_first_datetime64(self):
738738
def test_groupby_max_datetime64(self):
739739
# GH 5869
740740
# datetimelike dtype conversion from int
741-
df = DataFrame({"A": Timestamp("20130101"), "B": np.arange(5)})
741+
df = DataFrame({"A": Timestamp("20130101").as_unit("s"), "B": np.arange(5)})
742742
# TODO: can we retain second reso in .apply here?
743743
expected = df.groupby("A")["A"].apply(lambda x: x.max()).astype("M8[s]")
744744
result = df.groupby("A")["A"].max()

pandas/tests/indexes/datetimes/test_constructors.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def test_construction_dti_with_mixed_timezones(self):
524524
Timestamp("2011-01-01 10:00", tz="Asia/Tokyo"),
525525
Timestamp("2011-01-02 10:00", tz="US/Eastern"),
526526
],
527-
dtype="M8[s, US/Eastern]",
527+
dtype="M8[us, US/Eastern]",
528528
name="idx",
529529
)
530530
tm.assert_index_equal(dti, expected)
@@ -602,7 +602,7 @@ def test_constructor_coverage(self):
602602
expected = DatetimeIndex(strings.astype("O"))
603603
tm.assert_index_equal(result, expected)
604604

605-
from_ints = DatetimeIndex(expected.as_unit("ns").asi8).as_unit("s")
605+
from_ints = DatetimeIndex(expected.as_unit("ns").asi8).as_unit("us")
606606
tm.assert_index_equal(from_ints, expected)
607607

608608
# string with NaT
@@ -611,7 +611,7 @@ def test_constructor_coverage(self):
611611
expected = DatetimeIndex(strings.astype("O"))
612612
tm.assert_index_equal(result, expected)
613613

614-
from_ints = DatetimeIndex(expected.as_unit("ns").asi8).as_unit("s")
614+
from_ints = DatetimeIndex(expected.as_unit("ns").asi8).as_unit("us")
615615
tm.assert_index_equal(from_ints, expected)
616616

617617
# non-conforming
@@ -940,11 +940,11 @@ def test_dti_tz_constructors(self, tzstr):
940940

941941
idx1 = to_datetime(arr).tz_localize(tzstr)
942942
idx2 = date_range(
943-
start="2005-11-10 08:00:00", freq="h", periods=2, tz=tzstr, unit="s"
943+
start="2005-11-10 08:00:00", freq="h", periods=2, tz=tzstr, unit="us"
944944
)
945945
idx2 = idx2._with_freq(None) # the others all have freq=None
946-
idx3 = DatetimeIndex(arr, tz=tzstr).as_unit("s")
947-
idx4 = DatetimeIndex(np.array(arr), tz=tzstr).as_unit("s")
946+
idx3 = DatetimeIndex(arr, tz=tzstr)
947+
idx4 = DatetimeIndex(np.array(arr), tz=tzstr)
948948

949949
tm.assert_index_equal(idx1, idx2)
950950
tm.assert_index_equal(idx1, idx3)
@@ -1198,9 +1198,9 @@ def test_dti_constructor_object_dtype_dayfirst_yearfirst_with_tz(self):
11981198
yfirst = Timestamp(2005, 10, 16, tz="US/Pacific")
11991199

12001200
result1 = DatetimeIndex([val], tz="US/Pacific", dayfirst=True)
1201-
expected1 = DatetimeIndex([dfirst]).as_unit("s")
1201+
expected1 = DatetimeIndex([dfirst])
12021202
tm.assert_index_equal(result1, expected1)
12031203

12041204
result2 = DatetimeIndex([val], tz="US/Pacific", yearfirst=True)
1205-
expected2 = DatetimeIndex([yfirst]).as_unit("s")
1205+
expected2 = DatetimeIndex([yfirst])
12061206
tm.assert_index_equal(result2, expected2)

0 commit comments

Comments
 (0)