From ba5f438f5c641950c837443991f32c3d90662564 Mon Sep 17 00:00:00 2001 From: Antonio Gutierrez Date: Sat, 13 Jul 2019 16:42:24 +0200 Subject: [PATCH 1/3] arrays/period: allow parsing of PeriodDtype columns from read_csv Fixes: https://github.com/pandas-dev/pandas/issues/26934 Signed-off-by: Antonio Gutierrez --- doc/source/whatsnew/v0.25.0.rst | 1 + pandas/core/arrays/period.py | 4 ++++ pandas/tests/extension/test_period.py | 4 +--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index eeaafd7ad7d51..b35a7d311e9bc 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1186,6 +1186,7 @@ ExtensionArray - :meth:`Series.count` miscounts NA values in ExtensionArrays (:issue:`26835`) - Added ``Series.__array_ufunc__`` to better handle NumPy ufuncs applied to Series backed by extension arrays (:issue:`23293`). - Keyword argument ``deep`` has been removed from :meth:`ExtensionArray.copy` (:issue:`27083`) +- Allow parsing of `PeriodDType` columns when using `read_csv()` (:issue:`26934`) Other ^^^^^ diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 8291cb70affcd..b0336c46d1953 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -253,6 +253,10 @@ def _from_sequence( ordinals = libperiod.extract_ordinals(periods, freq) return cls(ordinals, freq=freq) + @classmethod + def _from_sequence_of_strings(cls, strings, dtype=None, copy=False): + return cls._from_sequence(strings, dtype, copy) + @classmethod def _from_datetime64(cls, data, freq, tz=None): """ diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 8a500e1be766e..c439b8b5ed319 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -158,6 +158,4 @@ class TestPrinting(BasePeriodTests, base.BasePrintingTests): class TestParsing(BasePeriodTests, base.BaseParsingTests): @pytest.mark.parametrize("engine", ["c", "python"]) def test_EA_types(self, engine, data): - expected_msg = r".*must implement _from_sequence_of_strings.*" - with pytest.raises(NotImplementedError, match=expected_msg): - super().test_EA_types(engine, data) + super().test_EA_types(engine, data) From 28d1364e63a5bc6f9e000b6fed5582f0a0c8ed36 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 15 Jul 2019 07:08:07 -0500 Subject: [PATCH 2/3] DOC: fixed ref --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index b35a7d311e9bc..24f714ed4bff4 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1186,7 +1186,7 @@ ExtensionArray - :meth:`Series.count` miscounts NA values in ExtensionArrays (:issue:`26835`) - Added ``Series.__array_ufunc__`` to better handle NumPy ufuncs applied to Series backed by extension arrays (:issue:`23293`). - Keyword argument ``deep`` has been removed from :meth:`ExtensionArray.copy` (:issue:`27083`) -- Allow parsing of `PeriodDType` columns when using `read_csv()` (:issue:`26934`) +- Allow parsing of :class:`PeriodDtype` columns when using `read_csv()` (:issue:`26934`) Other ^^^^^ From cca5c499a8f79d53cd804793f9dd86a16d523cf5 Mon Sep 17 00:00:00 2001 From: Antonio Gutierrez Date: Mon, 15 Jul 2019 20:44:57 +0200 Subject: [PATCH 3/3] doc: move what's new entry to correct section and use func Signed-off-by: Antonio Gutierrez --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 24f714ed4bff4..40268528377cc 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1103,6 +1103,7 @@ I/O - Bug in :meth:`read_hdf` where reading a timezone aware :class:`DatetimeIndex` would raise a ``TypeError`` (:issue:`11926`) - Bug in :meth:`to_msgpack` and :meth:`read_msgpack` which would raise a ``ValueError`` rather than a ``FileNotFoundError`` for an invalid path (:issue:`27160`) - Fixed bug in :meth:`DataFrame.to_parquet` which would raise a ``ValueError`` when the dataframe had no columns (:issue:`27339`) +- Allow parsing of :class:`PeriodDtype` columns when using :func:`read_csv` (:issue:`26934`) Plotting ^^^^^^^^ @@ -1186,7 +1187,6 @@ ExtensionArray - :meth:`Series.count` miscounts NA values in ExtensionArrays (:issue:`26835`) - Added ``Series.__array_ufunc__`` to better handle NumPy ufuncs applied to Series backed by extension arrays (:issue:`23293`). - Keyword argument ``deep`` has been removed from :meth:`ExtensionArray.copy` (:issue:`27083`) -- Allow parsing of :class:`PeriodDtype` columns when using `read_csv()` (:issue:`26934`) Other ^^^^^