pandas icon indicating copy to clipboard operation
pandas copied to clipboard

CLN: replace unnecessary `freq_to_period_freqstr` with `PeriodDtype` constructor

Open natmokval opened this issue 1 year ago • 1 comments

xref #52064

replaced freq_to_period_freqstr() with PeriodDtype(freq)._freqstr in ValueError message in the definition of _shift_with_freq()

natmokval avatar Dec 18 '23 13:12 natmokval

I replaced freq_to_period_freqstr with PeriodDtype(obj)._freqstr / PeriodDtypeBase(obj._period_dtype_code, obj.n)._freqstr. Now we don’t need the function freq_to_period_freqstr, which is why I removed it.

One comment: In pandas/core/arrays/period.py in the definition of raise_on_incompatible I added

with warnings.catch_warnings():
    warnings.simplefilter("ignore")

because otherwise the test_maybe_convert_timedelta (in pandas/tests/indexes/period/test_period.py) fail.

@MarcoGorelli, could you please take a look at this PR?

natmokval avatar Feb 14 '24 12:02 natmokval

Thanks @natmokval

mroeschke avatar Feb 28 '24 17:02 mroeschke