Skip to content

Commit a5087dd

Browse files
Fixed bytes encoding for pandas codec (#2117)
1 parent 0328b65 commit a5087dd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

mlserver/codecs/pandas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ def _process_bytes(
8181
content_type: Optional[str] = StringCodec.ContentType
8282
for elem in data:
8383
converted = elem
84-
if not isinstance(elem, str):
84+
if not isinstance(elem, (str, bytes)):
8585
# There was a non-string element, so we can't determine a content
8686
# type
8787
content_type = None
88-
elif use_bytes:
88+
elif isinstance(elem, str) and use_bytes:
8989
converted = encode_str(elem)
9090

9191
processed.append(converted)

tests/codecs/test_pandas.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ def test_can_encode(payload: Any, expected: bool):
3232
@pytest.mark.parametrize(
3333
"series, use_bytes, expected",
3434
[
35+
(
36+
pd.Series(data=[b"hey", b"abc"], name="foo"),
37+
True,
38+
ResponseOutput(
39+
name="foo",
40+
shape=[2, 1],
41+
data=[b"hey", b"abc"],
42+
datatype="BYTES",
43+
parameters=Parameters(content_type=StringCodec.ContentType),
44+
),
45+
),
46+
(
47+
pd.Series(data=[b"hey", b"abc"], name="foo"),
48+
False,
49+
ResponseOutput(
50+
name="foo",
51+
shape=[2, 1],
52+
data=[b"hey", b"abc"],
53+
datatype="BYTES",
54+
parameters=Parameters(content_type=StringCodec.ContentType),
55+
),
56+
),
3557
(
3658
pd.Series(data=["hey", "abc"], name="foo"),
3759
True,

0 commit comments

Comments
 (0)