Skip to content

Commit 0dfe989

Browse files
authored
REF: add Resolution to tslibs.__init__, rename _resolution->_resolution_obj (pandas-dev#34518)
1 parent 3970153 commit 0dfe989

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

pandas/_libs/tslibs/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"OutOfBoundsDatetime",
99
"IncompatibleFrequency",
1010
"Period",
11+
"Resolution",
1112
"Timedelta",
1213
"delta_to_nanoseconds",
1314
"ints_to_pytimedelta",
@@ -20,6 +21,7 @@
2021
from .nattype import NaT, NaTType, iNaT, is_null_datetimelike, nat_strings
2122
from .np_datetime import OutOfBoundsDatetime
2223
from .period import IncompatibleFrequency, Period
24+
from .resolution import Resolution
2325
from .timedeltas import Timedelta, delta_to_nanoseconds, ints_to_pytimedelta
2426
from .timestamps import Timestamp
2527
from .tzconversion import tz_convert_single

pandas/core/arrays/datetimelike.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55

66
import numpy as np
77

8-
from pandas._libs import NaT, NaTType, Period, Timestamp, algos, iNaT, lib
9-
from pandas._libs.tslibs.resolution import Resolution
10-
from pandas._libs.tslibs.timedeltas import delta_to_nanoseconds
8+
from pandas._libs import algos, lib
9+
from pandas._libs.tslibs import (
10+
NaT,
11+
NaTType,
12+
Period,
13+
Resolution,
14+
Timestamp,
15+
delta_to_nanoseconds,
16+
iNaT,
17+
)
1118
from pandas._libs.tslibs.timestamps import (
1219
RoundTo,
1320
integer_op_not_supported,
@@ -1103,7 +1110,7 @@ def inferred_freq(self):
11031110
return None
11041111

11051112
@property # NB: override with cache_readonly in immutable subclasses
1106-
def _resolution(self) -> Optional[Resolution]:
1113+
def _resolution_obj(self) -> Optional[Resolution]:
11071114
try:
11081115
return Resolution.get_reso_from_freq(self.freqstr)
11091116
except KeyError:
@@ -1114,12 +1121,12 @@ def resolution(self) -> str:
11141121
"""
11151122
Returns day, hour, minute, second, millisecond or microsecond
11161123
"""
1117-
if self._resolution is None:
1124+
if self._resolution_obj is None:
11181125
if is_period_dtype(self.dtype):
11191126
# somewhere in the past it was decided we default to day
11201127
return "day"
11211128
# otherwise we fall through and will raise
1122-
return Resolution.get_str(self._resolution)
1129+
return Resolution.get_str(self._resolution_obj)
11231130

11241131
@classmethod
11251132
def _validate_frequency(cls, index, freq, **kwargs):

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def is_normalized(self):
537537
return conversion.is_date_array_normalized(self.asi8, self.tz)
538538

539539
@property # NB: override with cache_readonly in immutable subclasses
540-
def _resolution(self) -> libresolution.Resolution:
540+
def _resolution_obj(self) -> libresolution.Resolution:
541541
return libresolution.get_resolution(self.asi8, self.tz)
542542

543543
# ----------------------------------------------------------------

pandas/core/indexes/datetimelike.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88

99
from pandas._libs import NaT, Timedelta, iNaT, join as libjoin, lib
10-
from pandas._libs.tslibs import timezones
10+
from pandas._libs.tslibs import Resolution, timezones
1111
from pandas._libs.tslibs.parsing import DateParseError
1212
from pandas._typing import Label
1313
from pandas.compat.numpy import function as nv
@@ -78,7 +78,7 @@ def wrapper(left, right):
7878

7979

8080
@inherit_names(
81-
["inferred_freq", "_isnan", "_resolution", "resolution"],
81+
["inferred_freq", "_isnan", "_resolution_obj", "resolution"],
8282
DatetimeLikeArrayMixin,
8383
cache=True,
8484
)
@@ -93,7 +93,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex):
9393
_data: Union[DatetimeArray, TimedeltaArray, PeriodArray]
9494
freq: Optional[DateOffset]
9595
freqstr: Optional[str]
96-
_resolution: int
96+
_resolution_obj: Resolution
9797
_bool_ops: List[str] = []
9898
_field_ops: List[str] = []
9999

pandas/core/indexes/datetimes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77

88
from pandas._libs import NaT, Period, Timestamp, index as libindex, lib, tslib
9-
from pandas._libs.tslibs import fields, parsing, resolution as libresolution, timezones
9+
from pandas._libs.tslibs import Resolution, fields, parsing, timezones
1010
from pandas._libs.tslibs.frequencies import get_freq_group
1111
from pandas._libs.tslibs.offsets import prefix_mapping
1212
from pandas._typing import DtypeObj, Label
@@ -72,7 +72,9 @@ def _new_DatetimeIndex(cls, d):
7272
DatetimeArray,
7373
wrap=True,
7474
)
75-
@inherit_names(["_timezone", "is_normalized", "_resolution"], DatetimeArray, cache=True)
75+
@inherit_names(
76+
["_timezone", "is_normalized", "_resolution_obj"], DatetimeArray, cache=True
77+
)
7678
@inherit_names(
7779
[
7880
"_bool_ops",
@@ -525,7 +527,7 @@ def _validate_partial_date_slice(self, reso: str):
525527
if (
526528
self.is_monotonic
527529
and reso in ["day", "hour", "minute", "second"]
528-
and self._resolution >= libresolution.Resolution.from_attrname(reso)
530+
and self._resolution_obj >= Resolution.from_attrname(reso)
529531
):
530532
# These resolution/monotonicity validations came from GH3931,
531533
# GH3452 and GH2369.

pandas/tests/tslibs/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_namespace():
3333
"OutOfBoundsDatetime",
3434
"Period",
3535
"IncompatibleFrequency",
36+
"Resolution",
3637
"Timedelta",
3738
"Timestamp",
3839
"delta_to_nanoseconds",

0 commit comments

Comments
 (0)