From 040fccf3b001cfd679460f0a668771673ee4a793 Mon Sep 17 00:00:00 2001 From: BettyJJ <245282+BettyJJ@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:50:27 +0200 Subject: [PATCH] add encoding support to the read() method --- st_files_connection/connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/st_files_connection/connection.py b/st_files_connection/connection.py index ada62a0..4aff170 100644 --- a/st_files_connection/connection.py +++ b/st_files_connection/connection.py @@ -148,7 +148,7 @@ def _read_csv(path: str | Path, **kwargs) -> pd.DataFrame: if "connection_name" in kwargs: kwargs.pop("connection_name") - with self.open(path, "rt") as f: + with self.open(path, "rt", encoding=kwargs.get("encoding")) as f: return pd.read_csv(f, **kwargs) @cache_data(ttl=ttl, show_spinner="Running `files.read(...)`.") @@ -166,7 +166,7 @@ def _read_json(path: str | Path, **kwargs) -> Any: if "connection_name" in kwargs: kwargs.pop("connection_name") - with self.open(path, "rt") as f: + with self.open(path, "rt", encoding=kwargs.get("encoding")) as f: return json.load(f, **kwargs) @cache_data(ttl=ttl, show_spinner="Running `files.read(...)`.") @@ -175,7 +175,7 @@ def _read_jsonl(path: str | Path, **kwargs) -> pd.DataFrame: kwargs.pop("connection_name") kwargs['lines'] = True - with self.open(path, "rt") as f: + with self.open(path, "rt", encoding=kwargs.get("encoding")) as f: return pd.read_json(f, **kwargs) # Try to infer input_format from file extension if missing