Skip to content

Commit 277864a

Browse files
Add type conversion for 3.8 support of rds load
1 parent 1a8a772 commit 277864a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pins/drivers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from pathlib import Path
22
from typing import Sequence
33

4+
import fsspec.implementations.local
5+
46
from .config import PINS_ENV_INSECURE_READ, get_allow_pickle_read
57
from .errors import PinsInsecureReadError
68
from .meta import Meta
@@ -126,7 +128,12 @@ def load_data(
126128

127129
# Equivalent to `rdata.read_rds(f)` but compatible with Python 3.8.
128130
# See https://github.com/rstudio/pins-python/pull/265
129-
parsed = rdata.parser.parse_file(f)
131+
if isinstance(f, fsspec.implementations.local.LocalFileOpener):
132+
# rdata requires f to be a BinaryIO object.
133+
io_f = f.f
134+
else:
135+
io_f = f
136+
parsed = rdata.parser.parse_file(io_f)
130137
return rdata.conversion.convert(parsed)
131138
except ModuleNotFoundError:
132139
raise ModuleNotFoundError(

0 commit comments

Comments
 (0)