Skip to content

Commit d37469f

Browse files
committed
Refinements
1 parent e19455d commit d37469f

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

doc/source/whatsnew/v2.3.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ Other enhancements
3737
updated to work correctly with NumPy >= 2 (:issue:`57739`)
3838
- :meth:`Series.str.decode` result now has ``StringDtype`` when ``future.infer_string`` is True (:issue:`60709`)
3939
- :meth:`~Series.to_hdf` and :meth:`~DataFrame.to_hdf` now round-trip with ``StringDtype`` (:issue:`60663`)
40+
- The :meth:`Series.str.decode` has gained the argument ``dtype`` to control the dtype of the result (:issue:`60940`)
4041
- The :meth:`~Series.cumsum`, :meth:`~Series.cummin`, and :meth:`~Series.cummax` reductions are now implemented for ``StringDtype`` columns when backed by PyArrow (:issue:`60633`)
4142
- The :meth:`~Series.sum` reduction is now implemented for ``StringDtype`` columns (:issue:`59853`)
42-
- The :meth:`Series.str.decode` has gained the argument ``dtype`` to control the dtype of the result (:issue:`???`)
4343

4444
.. ---------------------------------------------------------------------------
4545
.. _whatsnew_230.notable_bug_fixes:

pandas/core/strings/accessor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,8 @@ def decode(self, encoding, errors: str = "strict", dtype: str | DtypeObj = None)
21222122
object dtype. When ``None``, the dtype of the result is determined by
21232123
``pd.options.future.infer_string``.
21242124
2125+
.. versionadded:: 2.3.0
2126+
21252127
Returns
21262128
-------
21272129
Series or Index

pandas/tests/strings/test_strings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,23 @@ def test_decode_errors_kwarg():
602602

603603

604604
def test_decode_string_dtype(string_dtype):
605+
# https://github.com/pandas-dev/pandas/pull/60940
605606
ser = Series([b"a", b"b"])
606607
result = ser.str.decode("utf-8", dtype=string_dtype)
607608
expected = Series(["a", "b"], dtype=string_dtype)
608609
tm.assert_series_equal(result, expected)
609610

610611

611612
def test_decode_object_dtype(object_dtype):
613+
# https://github.com/pandas-dev/pandas/pull/60940
612614
ser = Series([b"a", rb"\ud800"])
613615
result = ser.str.decode("utf-8", dtype=object_dtype)
614616
expected = Series(["a", r"\ud800"], dtype=object_dtype)
615617
tm.assert_series_equal(result, expected)
616618

617619

618620
def test_decode_bad_dtype():
621+
# https://github.com/pandas-dev/pandas/pull/60940
619622
ser = Series([b"a", b"b"])
620623
msg = "dtype must be string or object, got dtype='int64'"
621624
with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)