Skip to content

CLN: avoid NpyDatetimeUnit in tests #50469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
npy_unit_to_abbrev,
tz_compare,
)
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit

from pandas.core.dtypes.dtypes import DatetimeTZDtype

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

@pytest.fixture
def reso(self, unit):
"""Fixture returning datetime resolution for a given time unit"""
return {
"s": NpyDatetimeUnit.NPY_FR_s.value,
"ms": NpyDatetimeUnit.NPY_FR_ms.value,
"us": NpyDatetimeUnit.NPY_FR_us.value,
}[unit]

@pytest.fixture
def dtype(self, unit, tz_naive_fixture):
tz = tz_naive_fixture
Expand Down Expand Up @@ -71,19 +61,19 @@ def dta(self, dta_dti):
dta, dti = dta_dti
return dta

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

assert dta.dtype == dtype
assert dta[0]._creso == reso
assert dta[0].unit == unit
assert tz_compare(dta.tz, dta[0].tz)
assert (dta[0] == dta[:1]).all()

@pytest.mark.parametrize(
"field", DatetimeArray._field_ops + DatetimeArray._bool_ops
)
def test_fields(self, unit, reso, field, dtype, dta_dti):
def test_fields(self, unit, field, dtype, dta_dti):
dta, dti = dta_dti

assert (dti == dta).all()
Expand Down Expand Up @@ -166,7 +156,7 @@ def test_time_date(self, dta_dti, meth):
expected = getattr(dti, meth)
tm.assert_numpy_array_equal(result, expected)

def test_format_native_types(self, unit, reso, dtype, dta_dti):
def test_format_native_types(self, unit, dtype, dta_dti):
# In this case we should get the same formatted values with our nano
# version dti._data as we do with the non-nano dta
dta, dti = dta_dti
Expand Down
17 changes: 2 additions & 15 deletions pandas/tests/arrays/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import numpy as np
import pytest

from pandas._libs.tslibs.dtypes import NpyDatetimeUnit

import pandas as pd
from pandas import Timedelta
import pandas._testing as tm
Expand All @@ -19,28 +17,17 @@ class TestNonNano:
def unit(self, request):
return request.param

@pytest.fixture
def reso(self, unit):
if unit == "s":
return NpyDatetimeUnit.NPY_FR_s.value
elif unit == "ms":
return NpyDatetimeUnit.NPY_FR_ms.value
elif unit == "us":
return NpyDatetimeUnit.NPY_FR_us.value
else:
raise NotImplementedError(unit)

@pytest.fixture
def tda(self, unit):
arr = np.arange(5, dtype=np.int64).view(f"m8[{unit}]")
return TimedeltaArray._simple_new(arr, dtype=arr.dtype)

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

assert tda.dtype == arr.dtype
assert tda[0]._creso == reso
assert tda[0].unit == unit

@pytest.mark.parametrize("field", TimedeltaArray._field_ops)
def test_fields(self, tda, field):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
iNaT,
parsing,
)
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
from pandas.errors import (
OutOfBoundsDatetime,
OutOfBoundsTimedelta,
Expand Down Expand Up @@ -862,7 +861,7 @@ def test_to_datetime_dt64s_out_of_bounds(self, cache, dt):
# as of 2022-09-28, the Timestamp constructor has been updated
# to cast to M8[s] but to_datetime has not
ts = Timestamp(dt)
assert ts._creso == NpyDatetimeUnit.NPY_FR_s.value
assert ts.unit == "s"
assert ts.asm8 == dt

msg = "Out of bounds nanosecond timestamp"
Expand Down