Skip to content
Open
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ Period
- Bug in :meth:`Period.strftime` where unknown format directives (e.g. ``"%Q"``) silently produced platform-dependent output and crashed the Python process on Windows; an ``Invalid format string`` ``ValueError`` is now raised on all platforms (:issue:`53562`)
- Bug in :meth:`Period.to_timestamp` and :meth:`PeriodIndex.to_timestamp` returning incorrect timestamps when the target frequency normalized to nanoseconds (e.g. ``"1ns"``) or when converting a nanosecond ``Period`` to a coarser target frequency (:issue:`63760`)
- Bug in :meth:`Period.to_timestamp` and :meth:`PeriodIndex.to_timestamp` with ``how="end"`` losing nanosecond precision when the target frequency normalized to nanoseconds (e.g. ``"1ns"``); the target frequency is now also validated when ``how="end"`` (:issue:`63760`)
- Bug in :meth:`PeriodIndex.from_fields` raising ``AssertionError`` for a quarterly ``freq`` not anchored on December (e.g. ``QuarterEnd(startingMonth=2)``), even though the equivalent scalar :class:`Period` works (:issue:`55784`)
-

Plotting
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ def _range_from_fields(
else:
freq = to_offset(freq, is_period=True)
base = libperiod.freq_to_dtype_code(freq)
if base != FreqGroup.FR_QTR.value:
if FreqGroup.from_period_dtype_code(base) != FreqGroup.FR_QTR:
raise AssertionError("base must equal FR_QTR")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this reachable? if so, we should be raising something other than AssertionError


freqstr = freq.freqstr
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexes/period/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ def test_constructor_field_arrays(self):
exp = period_range("2007-01", periods=3, freq="M")
tm.assert_index_equal(idx, exp)

@pytest.mark.parametrize("starting_month", range(1, 13))
def test_from_fields_quarterly_non_december_anchor(self, starting_month):
# GH#55784 from_fields rejected any quarterly freq not anchored on
# December, even though the equivalent scalar Period works.
freq = offsets.QuarterEnd(startingMonth=starting_month)
result = PeriodIndex.from_fields(year=[2014], quarter=[3], freq=freq)
expected = Period(year=2014, quarter=3, freq=freq)
assert result[0] == expected
assert result.dtype == PeriodDtype(freq)

def test_constructor_nano(self):
idx = period_range(
start=Period(ordinal=1, freq="ns"),
Expand Down