Skip to content

Commit 7b63769

Browse files
jbrockmendeljreback
authored andcommitted
De-privatize tslibs functions (#21714)
1 parent 2f14faf commit 7b63769

File tree

16 files changed

+41
-44
lines changed

16 files changed

+41
-44
lines changed

pandas/_libs/tslibs/frequencies.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ opattern = re.compile(
2020
r'([+\-]?\d*|[+\-]?\d*\.\d*)\s*([A-Za-z]+([\-][\dA-Za-z\-]+)?)'
2121
)
2222

23-
_INVALID_FREQ_ERROR = "Invalid frequency: {0}"
23+
INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}"
2424

2525
# ---------------------------------------------------------------------
2626
# Period codes
@@ -220,7 +220,7 @@ cpdef _period_str_to_code(freqstr):
220220
try:
221221
return _period_code_map[freqstr]
222222
except KeyError:
223-
raise ValueError(_INVALID_FREQ_ERROR.format(freqstr))
223+
raise ValueError(INVALID_FREQ_ERR_MSG.format(freqstr))
224224

225225

226226
cpdef str get_freq_str(base, mult=1):

pandas/_libs/tslibs/period.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ def extract_ordinals(ndarray[object] values, freq):
895895
ordinals[i] = p.ordinal
896896

897897
if p.freqstr != freqstr:
898-
msg = _DIFFERENT_FREQ_INDEX.format(freqstr, p.freqstr)
898+
msg = DIFFERENT_FREQ_INDEX.format(freqstr, p.freqstr)
899899
raise IncompatibleFrequency(msg)
900900

901901
except AttributeError:
@@ -985,8 +985,8 @@ cdef ndarray[int64_t] localize_dt64arr_to_period(ndarray[int64_t] stamps,
985985

986986

987987
_DIFFERENT_FREQ = "Input has different freq={1} from Period(freq={0})"
988-
_DIFFERENT_FREQ_INDEX = ("Input has different freq={1} "
989-
"from PeriodIndex(freq={0})")
988+
DIFFERENT_FREQ_INDEX = ("Input has different freq={1} "
989+
"from PeriodIndex(freq={0})")
990990

991991

992992
class IncompatibleFrequency(ValueError):

pandas/core/indexes/accessors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from pandas.core.accessor import PandasDelegate
1616
from pandas.core.base import NoNewAttributesMixin, PandasObject
1717
from pandas.core.indexes.datetimes import DatetimeIndex
18-
from pandas._libs.tslibs.period import IncompatibleFrequency # noqa
1918
from pandas.core.indexes.period import PeriodIndex
2019
from pandas.core.indexes.timedeltas import TimedeltaIndex
2120
from pandas.core.algorithms import take_1d

pandas/core/indexes/datetimelike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from pandas._libs import lib, iNaT, NaT, Timedelta
1616
from pandas._libs.tslibs.period import (Period, IncompatibleFrequency,
17-
_DIFFERENT_FREQ_INDEX)
17+
DIFFERENT_FREQ_INDEX)
1818
from pandas._libs.tslibs.timestamps import round_ns
1919

2020
from pandas.core.dtypes.common import (
@@ -732,7 +732,7 @@ def _sub_period_array(self, other):
732732
if not len(self) == len(other):
733733
raise ValueError("cannot subtract indices of unequal length")
734734
if self.freq != other.freq:
735-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
735+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
736736
raise IncompatibleFrequency(msg)
737737

738738
new_values = checked_add_with_arr(self.asi8, -other.asi8,

pandas/core/indexes/period.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from pandas._libs import tslib, index as libindex
3131
from pandas._libs.tslibs.period import (Period, IncompatibleFrequency,
3232
get_period_field_arr,
33+
DIFFERENT_FREQ_INDEX,
3334
_validate_end_alias, _quarter_to_myear)
3435
from pandas._libs.tslibs.fields import isleapyear_arr
3536
from pandas._libs.tslibs import resolution, period
@@ -71,9 +72,6 @@ def dt64arr_to_periodarr(data, freq, tz):
7172
# --- Period index sketch
7273

7374

74-
_DIFFERENT_FREQ_INDEX = period._DIFFERENT_FREQ_INDEX
75-
76-
7775
def _period_index_cmp(opname, cls):
7876
"""
7977
Wrap comparison operations to convert Period-like to PeriodDtype
@@ -84,13 +82,13 @@ def wrapper(self, other):
8482
op = getattr(self._ndarray_values, opname)
8583
if isinstance(other, Period):
8684
if other.freq != self.freq:
87-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
85+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
8886
raise IncompatibleFrequency(msg)
8987

9088
result = op(other.ordinal)
9189
elif isinstance(other, PeriodIndex):
9290
if other.freq != self.freq:
93-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
91+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
9492
raise IncompatibleFrequency(msg)
9593

9694
result = op(other._ndarray_values)
@@ -523,7 +521,7 @@ def astype(self, dtype, copy=True, how='start'):
523521
def searchsorted(self, value, side='left', sorter=None):
524522
if isinstance(value, Period):
525523
if value.freq != self.freq:
526-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, value.freqstr)
524+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, value.freqstr)
527525
raise IncompatibleFrequency(msg)
528526
value = value.ordinal
529527
elif isinstance(value, compat.string_types):
@@ -706,7 +704,7 @@ def _maybe_convert_timedelta(self, other):
706704
base = frequencies.get_base_alias(freqstr)
707705
if base == self.freq.rule_code:
708706
return other.n
709-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
707+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
710708
raise IncompatibleFrequency(msg)
711709
elif is_integer(other):
712710
# integer is passed to .shift via
@@ -721,7 +719,7 @@ def _add_offset(self, other):
721719
assert not isinstance(other, Tick)
722720
base = frequencies.get_base_alias(other.rule_code)
723721
if base != self.freq.rule_code:
724-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
722+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
725723
raise IncompatibleFrequency(msg)
726724
return self.shift(other.n)
727725

@@ -753,7 +751,7 @@ def _sub_period(self, other):
753751
# If the operation is well-defined, we return an object-Index
754752
# of DateOffsets. Null entries are filled with pd.NaT
755753
if self.freq != other.freq:
756-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
754+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
757755
raise IncompatibleFrequency(msg)
758756

759757
asi8 = self.asi8
@@ -837,7 +835,7 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
837835
target = _ensure_index(target)
838836

839837
if hasattr(target, 'freq') and target.freq != self.freq:
840-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, target.freqstr)
838+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, target.freqstr)
841839
raise IncompatibleFrequency(msg)
842840

843841
if isinstance(target, PeriodIndex):
@@ -1010,7 +1008,7 @@ def _assert_can_do_setop(self, other):
10101008
raise ValueError('can only call with other PeriodIndex-ed objects')
10111009

10121010
if self.freq != other.freq:
1013-
msg = _DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
1011+
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
10141012
raise IncompatibleFrequency(msg)
10151013

10161014
def _wrap_union_result(self, other, result):

pandas/tests/indexes/datetimes/test_scalar_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_round(self, tz):
101101
tm.assert_index_equal(rng.round(freq='H'), expected_rng)
102102
assert elt.round(freq='H') == expected_elt
103103

104-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
104+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
105105
with tm.assert_raises_regex(ValueError, msg):
106106
rng.round(freq='foo')
107107
with tm.assert_raises_regex(ValueError, msg):

pandas/tests/indexes/period/test_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_to_period_monthish(self):
167167
prng = rng.to_period()
168168
assert prng.freq == 'M'
169169

170-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
170+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
171171
with tm.assert_raises_regex(ValueError, msg):
172172
date_range('01-Jan-2012', periods=8, freq='EOM')
173173

pandas/tests/indexes/timedeltas/test_scalar_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_tdi_round(self):
5050
tm.assert_index_equal(td.round(freq='H'), expected_rng)
5151
assert elt.round(freq='H') == expected_elt
5252

53-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
53+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
5454
with tm.assert_raises_regex(ValueError, msg):
5555
td.round(freq='foo')
5656
with tm.assert_raises_regex(ValueError, msg):

pandas/tests/scalar/period/test_asfreq.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ def test_conv_weekly(self):
325325

326326
assert ival_W.asfreq('W') == ival_W
327327

328-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
328+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
329329
with tm.assert_raises_regex(ValueError, msg):
330330
ival_W.asfreq('WK')
331331

332332
def test_conv_weekly_legacy(self):
333333
# frequency conversion tests: from Weekly Frequency
334-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
334+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
335335
with tm.assert_raises_regex(ValueError, msg):
336336
Period(freq='WK', year=2007, month=1, day=1)
337337

@@ -738,7 +738,7 @@ def test_asfreq_MS(self):
738738

739739
assert initial.asfreq(freq="M", how="S") == Period('2013-01', 'M')
740740

741-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
741+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
742742
with tm.assert_raises_regex(ValueError, msg):
743743
initial.asfreq(freq="MS", how="S")
744744

pandas/tests/scalar/period/test_period.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def test_period_deprecated_freq(self):
515515
"U": ["MICROSECOND", "MICROSECONDLY", "microsecond"],
516516
"N": ["NANOSECOND", "NANOSECONDLY", "nanosecond"]}
517517

518-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
518+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
519519
for exp, freqs in iteritems(cases):
520520
for freq in freqs:
521521
with tm.assert_raises_regex(ValueError, msg):
@@ -759,7 +759,7 @@ def test_properties_weekly_legacy(self):
759759
exp = Period(freq='W', year=2012, month=2, day=1)
760760
assert exp.days_in_month == 29
761761

762-
msg = pd._libs.tslibs.frequencies._INVALID_FREQ_ERROR
762+
msg = pd._libs.tslibs.frequencies.INVALID_FREQ_ERR_MSG
763763
with tm.assert_raises_regex(ValueError, msg):
764764
Period(freq='WK', year=2007, month=1, day=7)
765765

0 commit comments

Comments
 (0)