Skip to content

Commit aaa9cd0

Browse files
authored
1 parent 80ba4c4 commit aaa9cd0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ Reshaping
10581058
- Bug in :func:`Dataframe.aggregate` and :func:`Series.aggregate` was causing recursive loop in some cases (:issue:`34224`)
10591059
- Fixed bug in :func:`melt` where melting MultiIndex columns with ``col_level`` > 0 would raise a ``KeyError`` on ``id_vars`` (:issue:`34129`)
10601060
- Bug in :meth:`Series.where` with an empty Series and empty ``cond`` having non-bool dtype (:issue:`34592`)
1061+
- Fixed regression where :meth:`DataFrame.apply` would raise ``ValueError`` for elements whth ``S`` dtype (:issue:`34529`)
10611062

10621063
Sparse
10631064
^^^^^^

pandas/core/dtypes/cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ def construct_1d_ndarray_preserving_na(
16081608
"""
16091609
subarr = np.array(values, dtype=dtype, copy=copy)
16101610

1611-
if dtype is not None and dtype.kind in ("U", "S"):
1611+
if dtype is not None and dtype.kind == "U":
16121612
# GH-21083
16131613
# We can't just return np.array(subarr, dtype='str') since
16141614
# NumPy will convert the non-string objects into strings

pandas/tests/frame/test_apply.py

+11
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,17 @@ def non_reducing_function(val):
785785
df.applymap(func)
786786
assert values == df.a.to_list()
787787

788+
def test_apply_with_byte_string(self):
789+
# GH 34529
790+
df = pd.DataFrame(np.array([b"abcd", b"efgh"]), columns=["col"])
791+
expected = pd.DataFrame(
792+
np.array([b"abcd", b"efgh"]), columns=["col"], dtype=object
793+
)
794+
# After we make the aply we exect a dataframe just
795+
# like the original but with the object datatype
796+
result = df.apply(lambda x: x.astype("object"))
797+
tm.assert_frame_equal(result, expected)
798+
788799

789800
class TestInferOutputShape:
790801
# the user has supplied an opaque UDF where

0 commit comments

Comments
 (0)