Skip to content

Commit 89d79c5

Browse files
chibby0nejreback
authored andcommitted
arrays/period: allow parsing of PeriodDtype columns from read_csv (#27380)
1 parent a373e0e commit 89d79c5

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ I/O
11471147
- Bug in :meth:`read_hdf` where reading a timezone aware :class:`DatetimeIndex` would raise a ``TypeError`` (:issue:`11926`)
11481148
- Bug in :meth:`to_msgpack` and :meth:`read_msgpack` which would raise a ``ValueError`` rather than a ``FileNotFoundError`` for an invalid path (:issue:`27160`)
11491149
- Fixed bug in :meth:`DataFrame.to_parquet` which would raise a ``ValueError`` when the dataframe had no columns (:issue:`27339`)
1150+
- Allow parsing of :class:`PeriodDtype` columns when using :func:`read_csv` (:issue:`26934`)
11501151
11511152
Plotting
11521153
^^^^^^^^

pandas/core/arrays/period.py

+4
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ def _from_sequence(
253253
ordinals = libperiod.extract_ordinals(periods, freq)
254254
return cls(ordinals, freq=freq)
255255

256+
@classmethod
257+
def _from_sequence_of_strings(cls, strings, dtype=None, copy=False):
258+
return cls._from_sequence(strings, dtype, copy)
259+
256260
@classmethod
257261
def _from_datetime64(cls, data, freq, tz=None):
258262
"""

pandas/tests/extension/test_period.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,4 @@ class TestPrinting(BasePeriodTests, base.BasePrintingTests):
158158
class TestParsing(BasePeriodTests, base.BaseParsingTests):
159159
@pytest.mark.parametrize("engine", ["c", "python"])
160160
def test_EA_types(self, engine, data):
161-
expected_msg = r".*must implement _from_sequence_of_strings.*"
162-
with pytest.raises(NotImplementedError, match=expected_msg):
163-
super().test_EA_types(engine, data)
161+
super().test_EA_types(engine, data)

0 commit comments

Comments
 (0)