diff --git a/src/datasets/io/json.py b/src/datasets/io/json.py index ae4710e0726..2d4698df966 100644 --- a/src/datasets/io/json.py +++ b/src/datasets/io/json.py @@ -95,7 +95,10 @@ def write(self) -> int: lines = self.to_json_kwargs.pop("lines", True if orient == "records" else False) if "index" not in self.to_json_kwargs and orient in ["split", "table"]: self.to_json_kwargs["index"] = False - compression = self.to_json_kwargs.pop("compression", None) + + # Determine the default compression value based on self.path_or_buf type + default_compression = "infer" if isinstance(self.path_or_buf, (str, bytes, os.PathLike)) else None + compression = self.to_json_kwargs.pop("compression", default_compression) if compression not in [None, "infer", "gzip", "bz2", "xz"]: raise NotImplementedError(f"`datasets` currently does not support {compression} compression")