Skip to content

Commit d07c58d

Browse files
phoflluckyvs1
authored andcommitted
Regression in replace raising ValueError for bytes object (pandas-dev#39065)
1 parent ecf18b9 commit d07c58d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/source/whatsnew/v1.2.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Fixed regressions
2626
- Bug in :meth:`read_csv` with ``float_precision="high"`` caused segfault or wrong parsing of long exponent strings. This resulted in a regression in some cases as the default for ``float_precision`` was changed in pandas 1.2.0 (:issue:`38753`)
2727
- Fixed regression in :meth:`Rolling.skew` and :meth:`Rolling.kurt` modifying the object inplace (:issue:`38908`)
2828
- Fixed regression in :meth:`read_csv` and other read functions were the encoding error policy (``errors``) did not default to ``"replace"`` when no encoding was specified (:issue:`38989`)
29+
- Fixed regression in :meth:`DataFrame.replace` raising ValueError when :class:`DataFrame` has dtype ``bytes`` (:issue:`38900`)
2930

3031
.. ---------------------------------------------------------------------------
3132

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ class ObjectBlock(Block):
22932293
_can_hold_na = True
22942294

22952295
def _maybe_coerce_values(self, values):
2296-
if issubclass(values.dtype.type, str):
2296+
if issubclass(values.dtype.type, (str, bytes)):
22972297
values = np.array(values, dtype=object)
22982298
return values
22992299

pandas/tests/frame/methods/test_replace.py

+7
Original file line numberDiff line numberDiff line change
@@ -1636,3 +1636,10 @@ def test_replace_unicode(self):
16361636
result = df1.replace(columns_values_map)
16371637
expected = DataFrame({"positive": np.ones(3)})
16381638
tm.assert_frame_equal(result, expected)
1639+
1640+
def test_replace_bytes(self, frame_or_series):
1641+
# GH#38900
1642+
obj = frame_or_series(["o"]).astype("|S")
1643+
expected = obj.copy()
1644+
obj = obj.replace({None: np.nan})
1645+
tm.assert_equal(obj, expected)

0 commit comments

Comments
 (0)