Skip to content

Commit 8f760d2

Browse files
committed
BUG: AttributeError when read_sas used with GCS
With GCSFS (and possibly other connectors), the output from they file read is `bytes`, not a Unicode `str`. The `encode` call is unnecessary in this case.
1 parent c47e9ca commit 8f760d2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pandas/io/sas/sas_xport.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ def __init__(
266266
# Copy to BytesIO, and ensure no encoding
267267
contents = filepath_or_buffer.read()
268268
try:
269-
contents = contents.encode(self._encoding)
269+
# Convert string output to bytes, if needed
270+
if hasattr(contents, "encode"):
271+
contents = contents.encode(self._encoding)
270272
except UnicodeEncodeError:
271273
pass
272274
self.filepath_or_buffer = BytesIO(contents)

0 commit comments

Comments
 (0)