Skip to content

Commit e423eee

Browse files
authored
CLN: avoid NpyDatetimeUnit in tests (#50469)
1 parent 83c2a5f commit e423eee

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

pandas/tests/arrays/test_datetimes.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
npy_unit_to_abbrev,
1717
tz_compare,
1818
)
19-
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
2019

2120
from pandas.core.dtypes.dtypes import DatetimeTZDtype
2221

@@ -34,15 +33,6 @@ def unit(self, request):
3433
"""Fixture returning parametrized time units"""
3534
return request.param
3635

37-
@pytest.fixture
38-
def reso(self, unit):
39-
"""Fixture returning datetime resolution for a given time unit"""
40-
return {
41-
"s": NpyDatetimeUnit.NPY_FR_s.value,
42-
"ms": NpyDatetimeUnit.NPY_FR_ms.value,
43-
"us": NpyDatetimeUnit.NPY_FR_us.value,
44-
}[unit]
45-
4636
@pytest.fixture
4737
def dtype(self, unit, tz_naive_fixture):
4838
tz = tz_naive_fixture
@@ -71,19 +61,19 @@ def dta(self, dta_dti):
7161
dta, dti = dta_dti
7262
return dta
7363

74-
def test_non_nano(self, unit, reso, dtype):
64+
def test_non_nano(self, unit, dtype):
7565
arr = np.arange(5, dtype=np.int64).view(f"M8[{unit}]")
7666
dta = DatetimeArray._simple_new(arr, dtype=dtype)
7767

7868
assert dta.dtype == dtype
79-
assert dta[0]._creso == reso
69+
assert dta[0].unit == unit
8070
assert tz_compare(dta.tz, dta[0].tz)
8171
assert (dta[0] == dta[:1]).all()
8272

8373
@pytest.mark.parametrize(
8474
"field", DatetimeArray._field_ops + DatetimeArray._bool_ops
8575
)
86-
def test_fields(self, unit, reso, field, dtype, dta_dti):
76+
def test_fields(self, unit, field, dtype, dta_dti):
8777
dta, dti = dta_dti
8878

8979
assert (dti == dta).all()
@@ -166,7 +156,7 @@ def test_time_date(self, dta_dti, meth):
166156
expected = getattr(dti, meth)
167157
tm.assert_numpy_array_equal(result, expected)
168158

169-
def test_format_native_types(self, unit, reso, dtype, dta_dti):
159+
def test_format_native_types(self, unit, dtype, dta_dti):
170160
# In this case we should get the same formatted values with our nano
171161
# version dti._data as we do with the non-nano dta
172162
dta, dti = dta_dti

pandas/tests/arrays/test_timedeltas.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import numpy as np
44
import pytest
55

6-
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
7-
86
import pandas as pd
97
from pandas import Timedelta
108
import pandas._testing as tm
@@ -19,28 +17,17 @@ class TestNonNano:
1917
def unit(self, request):
2018
return request.param
2119

22-
@pytest.fixture
23-
def reso(self, unit):
24-
if unit == "s":
25-
return NpyDatetimeUnit.NPY_FR_s.value
26-
elif unit == "ms":
27-
return NpyDatetimeUnit.NPY_FR_ms.value
28-
elif unit == "us":
29-
return NpyDatetimeUnit.NPY_FR_us.value
30-
else:
31-
raise NotImplementedError(unit)
32-
3320
@pytest.fixture
3421
def tda(self, unit):
3522
arr = np.arange(5, dtype=np.int64).view(f"m8[{unit}]")
3623
return TimedeltaArray._simple_new(arr, dtype=arr.dtype)
3724

38-
def test_non_nano(self, unit, reso):
25+
def test_non_nano(self, unit):
3926
arr = np.arange(5, dtype=np.int64).view(f"m8[{unit}]")
4027
tda = TimedeltaArray._simple_new(arr, dtype=arr.dtype)
4128

4229
assert tda.dtype == arr.dtype
43-
assert tda[0]._creso == reso
30+
assert tda[0].unit == unit
4431

4532
@pytest.mark.parametrize("field", TimedeltaArray._field_ops)
4633
def test_fields(self, tda, field):

pandas/tests/tools/test_to_datetime.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
iNaT,
2323
parsing,
2424
)
25-
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
2625
from pandas.errors import (
2726
OutOfBoundsDatetime,
2827
OutOfBoundsTimedelta,
@@ -867,7 +866,7 @@ def test_to_datetime_dt64s_out_of_bounds(self, cache, dt):
867866
# as of 2022-09-28, the Timestamp constructor has been updated
868867
# to cast to M8[s] but to_datetime has not
869868
ts = Timestamp(dt)
870-
assert ts._creso == NpyDatetimeUnit.NPY_FR_s.value
869+
assert ts.unit == "s"
871870
assert ts.asm8 == dt
872871

873872
msg = "Out of bounds nanosecond timestamp"

0 commit comments

Comments
 (0)