From 3feb7e37db3806af076f263dd4c6cecc97ae685e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 18 Feb 2020 18:14:57 +0000 Subject: [PATCH] REGR: Series.str.encode("base64") --- doc/source/whatsnew/v1.0.2.rst | 2 +- pandas/core/strings.py | 1 - pandas/tests/test_strings.py | 8 ++++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.0.2.rst b/doc/source/whatsnew/v1.0.2.rst index 19358689a2186..025924b1c0a5a 100644 --- a/doc/source/whatsnew/v1.0.2.rst +++ b/doc/source/whatsnew/v1.0.2.rst @@ -19,7 +19,7 @@ Fixed regressions - Fixed regression in :meth:`Series.align` when ``other`` is a DataFrame and ``method`` is not None (:issue:`31785`) - Fixed regression in :meth:`pandas.core.groupby.RollingGroupby.apply` where the ``raw`` parameter was ignored (:issue:`31754`) - Fixed regression in :meth:`rolling(..).corr() ` when using a time offset (:issue:`31789`) -- +- Fixed regression in :meth:`Series.str.encode` where ``base64`` was no longer valid for bytes objects (:issue:`32048`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 4b0fc3e47356c..017504d9f002a 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2898,7 +2898,6 @@ def decode(self, encoding, errors="strict"): return self._wrap_result(result, returns_string=False) @copy(str_encode) - @forbid_nonstring_types(["bytes"]) def encode(self, encoding, errors="strict"): result = str_encode(self._parent, encoding, errors) return self._wrap_result(result, returns_string=False) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 1338d801e39f4..f7d945f1f8879 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -3592,3 +3592,11 @@ def test_string_array_extract(): result = result.astype(object) tm.assert_equal(result, expected) + + +def test_bytes_encode(): + # gh-32049 + ser = pd.Series(list("abc")) + result = ser.str.encode(encoding="utf-8").str.encode(encoding="base64") + expected = pd.Series([b"YQ==\n", b"Yg==\n", b"Yw==\n"]) + tm.assert_series_equal(result, expected)