Skip to content

Commit fb7ad08

Browse files
author
Veronur
committed
GH34529
correction and test for issue-pandas-dev#34529 made the formating changes fixing tests on issue-pandas-dev#34529 add whats new entry on issue-pandas-dev#34539 add whats new entry correction issue-pandas-dev#34539
1 parent 6258397 commit fb7ad08

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
@@ -1032,6 +1032,7 @@ ExtensionArray
10321032
- Fixed bug where :meth:`StringArray.memory_usage` was not implemented (:issue:`33963`)
10331033
- Fixed bug where :meth:`DataFrameGroupBy` would ignore the ``min_count`` argument for aggregations on nullable boolean dtypes (:issue:`34051`)
10341034
- Fixed bug that `DataFrame(columns=.., dtype='string')` would fail (:issue:`27953`, :issue:`33623`)
1035+
- Fixed regression where :meth:`DataFrame.apply` would raise ``ValueError`` for elements whth ``S`` dtype (:issue:`34529`)
10351036

10361037
Other
10371038
^^^^^

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)