Skip to content

Commit b6eeed0

Browse files
committed
update tests
1 parent d761c9c commit b6eeed0

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

pandas/core/dtypes/missing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ def na_value_for_dtype(dtype: DtypeObj, compat: bool = True):
686686
if isinstance(dtype, ExtensionDtype):
687687
return dtype.na_value
688688
elif dtype.kind in "mM":
689-
return dtype.type("NaT", "ns")
689+
unit = np.datetime_data(dtype)[0]
690+
return dtype.type("NaT", unit)
690691
elif dtype.kind == "f":
691692
return np.nan
692693
elif dtype.kind in "iu":

pandas/tests/arithmetic/test_timedelta64.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def test_timedelta_ops_with_missing_values(self):
750750
with pytest.raises(TypeError, match=msg):
751751
# Passing datetime64-dtype data to TimedeltaIndex is no longer
752752
# supported GH#29794
753-
pd.to_timedelta(Series([NaT])) # TODO: belongs elsewhere?
753+
pd.to_timedelta(Series([NaT], dtype="M8[ns]")) # TODO: belongs elsewhere?
754754

755755
sn = pd.to_timedelta(Series([NaT], dtype="m8[ns]"))
756756

@@ -759,7 +759,9 @@ def test_timedelta_ops_with_missing_values(self):
759759
with pytest.raises(TypeError, match=msg):
760760
# Passing datetime64-dtype data to TimedeltaIndex is no longer
761761
# supported GH#29794
762-
DataFrame([NaT]).apply(pd.to_timedelta) # TODO: belongs elsewhere?
762+
DataFrame([NaT], dtype="M8[ns]").apply(
763+
pd.to_timedelta
764+
) # TODO: belongs elsewhere?
763765

764766
dfn = DataFrame([NaT._value]).apply(pd.to_timedelta)
765767

pandas/tests/arrays/categorical/test_missing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_compare_categorical_with_missing(self, a1, a2, categories):
204204
@pytest.mark.parametrize(
205205
"na_value, dtype",
206206
[
207-
(pd.NaT, "datetime64[ns]"),
207+
(pd.NaT, "datetime64[s]"),
208208
(None, "float64"),
209209
(np.nan, "float64"),
210210
(pd.NA, "float64"),

pandas/tests/frame/methods/test_combine_first.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ def test_combine_first_convert_datatime_correctly(
191191
df1, df2 = DataFrame({"a": data1}), DataFrame({"a": data2})
192192
result = df1.combine_first(df2)
193193
expected = DataFrame({"a": data_expected})
194-
if df1.isna().all(axis=None):
195-
expected = expected.astype("M8[ns]")
196-
# equiv: expected = expected.astype(df1["a"].dtype)
197194
tm.assert_frame_equal(result, expected)
198195

199196
def test_combine_first_align_nan(self):
@@ -449,7 +446,6 @@ def test_combine_first_timestamp_bug_NaT():
449446
expected = DataFrame(
450447
[[pd.NaT, datetime(2020, 1, 1), datetime(2020, 1, 2)]], columns=["a", "b", "c"]
451448
)
452-
expected["b"] = expected["b"].astype("M8[ns]")
453449

454450
tm.assert_frame_equal(result, expected)
455451

pandas/tests/frame/test_constructors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,9 @@ def test_constructor_datetimes_with_nulls(self, arr):
19951995
if isinstance(arr, np.ndarray):
19961996
# inferred from a pydatetime object
19971997
unit = "us"
1998+
elif not any(isinstance(x, np.datetime64) for y in arr for x in y):
1999+
# TODO: this condition is not clear about why we have different behavior
2000+
unit = "s"
19982001
expected = Series([np.dtype(f"datetime64[{unit}]")])
19992002
tm.assert_series_equal(result, expected)
20002003

pandas/tests/groupby/test_groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ def test_groupby_nat_exclude():
15481548
{"nan": [np.nan, np.nan, np.nan], "nat": [pd.NaT, pd.NaT, pd.NaT]}
15491549
)
15501550
assert nan_df["nan"].dtype == "float64"
1551-
assert nan_df["nat"].dtype == "datetime64[ns]"
1551+
assert nan_df["nat"].dtype == "datetime64[s]"
15521552

15531553
for key in ["nan", "nat"]:
15541554
grouped = nan_df.groupby(key)

pandas/tests/indexes/test_index_new.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ def test_infer_nat(self, val):
6060
values = [NaT, val]
6161

6262
idx = Index(values)
63-
assert idx.dtype == "datetime64[ns]" and idx.isna().all()
63+
assert idx.dtype == "datetime64[s]" and idx.isna().all()
6464

6565
idx = Index(values[::-1])
66-
assert idx.dtype == "datetime64[ns]" and idx.isna().all()
66+
assert idx.dtype == "datetime64[s]" and idx.isna().all()
6767

6868
idx = Index(np.array(values, dtype=object))
69-
assert idx.dtype == "datetime64[ns]" and idx.isna().all()
69+
assert idx.dtype == "datetime64[s]" and idx.isna().all()
7070

7171
idx = Index(np.array(values, dtype=object)[::-1])
72-
assert idx.dtype == "datetime64[ns]" and idx.isna().all()
72+
assert idx.dtype == "datetime64[s]" and idx.isna().all()
7373

7474
@pytest.mark.parametrize("na_value", [None, np.nan])
7575
@pytest.mark.parametrize("vtype", [list, tuple, iter])

pandas/tests/series/test_constructors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def test_constructor_pass_nan_nat(self):
763763
tm.assert_series_equal(Series(np.array([np.nan, np.nan])), exp)
764764

765765
exp = Series([NaT, NaT])
766-
assert exp.dtype == "datetime64[ns]"
766+
assert exp.dtype == "datetime64[s]"
767767
tm.assert_series_equal(Series([NaT, NaT]), exp)
768768
tm.assert_series_equal(Series(np.array([NaT, NaT])), exp)
769769

@@ -1220,7 +1220,7 @@ def test_construction_to_datetimelike_unit(self, arr_dtype, kind, unit):
12201220
def test_constructor_with_naive_string_and_datetimetz_dtype(self, arg):
12211221
# GH 17415: With naive string
12221222
result = Series([arg], dtype="datetime64[ns, CET]")
1223-
expected = Series(Timestamp(arg).as_unit("ns")).dt.tz_localize("CET")
1223+
expected = Series([Timestamp(arg)], dtype="M8[ns]").dt.tz_localize("CET")
12241224
tm.assert_series_equal(result, expected)
12251225

12261226
def test_constructor_datetime64_bigendian(self):
@@ -1583,7 +1583,7 @@ def test_NaT_scalar(self):
15831583
def test_NaT_cast(self):
15841584
# GH10747
15851585
result = Series([np.nan]).astype("M8[ns]")
1586-
expected = Series([NaT])
1586+
expected = Series([NaT], dtype="M8[ns]")
15871587
tm.assert_series_equal(result, expected)
15881588

15891589
def test_constructor_name_hashable(self):

0 commit comments

Comments
 (0)