Skip to content

Commit 0ad74d7

Browse files
authored
BUG: infer-objects raising for bytes Series (#50067)
* BUG: infer-objects raising for bytes Series * Merge remote-tracking branch 'upstream/main' into 49650 # Conflicts: # pandas/tests/series/methods/test_infer_objects.py
1 parent 03a981a commit 0ad74d7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/core/internals/blocks.py

+3
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,9 @@ def convert(
19691969
attempt to cast any object types to better types return a copy of
19701970
the block (if copy = True) by definition we ARE an ObjectBlock!!!!!
19711971
"""
1972+
if self.dtype != object:
1973+
return [self]
1974+
19721975
values = self.values
19731976
if values.ndim == 2:
19741977
# maybe_split ensures we only get here with values.shape[0] == 1,

pandas/tests/series/methods/test_infer_objects.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import numpy as np
22

3-
from pandas import interval_range
3+
from pandas import (
4+
Series,
5+
interval_range,
6+
)
47
import pandas._testing as tm
58

69

@@ -44,3 +47,10 @@ def test_infer_objects_interval(self, index_or_series):
4447

4548
result = obj.astype(object).infer_objects()
4649
tm.assert_equal(result, obj)
50+
51+
def test_infer_objects_bytes(self):
52+
# GH#49650
53+
ser = Series([b"a"], dtype="bytes")
54+
expected = ser.copy()
55+
result = ser.infer_objects()
56+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)