Skip to content

Commit bb41180

Browse files
committed
Replaced check for encoded with unencoded check to prevent edge cases where two values are different
1 parent 22fce11 commit bb41180

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pandas/io/stata.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,7 @@ def _encode_strings(self) -> None:
27392739
encoded = self.data[col].str.encode(self._encoding)
27402740
# If larger than _max_string_length do nothing
27412741
if (
2742-
max_len_string_array(ensure_object(encoded._values))
2742+
max_len_string_array(ensure_object(self.data[col]._values))
27432743
<= self._max_string_length
27442744
):
27452745
self.data[col] = encoded
@@ -3263,11 +3263,15 @@ def generate_blob(self, gso_table: dict[str, tuple[int, int]]) -> bytes:
32633263
bio.write(gso_type)
32643264

32653265
# llll
3266-
utf8_string = bytes(strl, "utf-8")
3267-
bio.write(struct.pack(len_type, len(utf8_string) + 1))
3266+
if(type(strl) == str):
3267+
strl_convert = bytes(strl, "utf-8")
3268+
else:
3269+
strl_convert = strl
3270+
3271+
bio.write(struct.pack(len_type, len(strl_convert) + 1))
32683272

32693273
# xxx...xxx
3270-
bio.write(utf8_string)
3274+
bio.write(strl_convert)
32713275
bio.write(null)
32723276

32733277
return bio.getvalue()

0 commit comments

Comments
 (0)