From 83a04d438c00974431d10eb685efd01868bd2053 Mon Sep 17 00:00:00 2001 From: Alex Burlacu Date: Fri, 11 Aug 2023 19:56:08 +0300 Subject: [PATCH] Adjust for pandas < 2.0 --- clearml/binding/artifacts.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/clearml/binding/artifacts.py b/clearml/binding/artifacts.py index 93062ebf..5577bf24 100644 --- a/clearml/binding/artifacts.py +++ b/clearml/binding/artifacts.py @@ -1,4 +1,5 @@ import gzip +import io import json import yaml import mimetypes @@ -1062,7 +1063,16 @@ class Artifacts(object): # (otherwise it is encoded and creates new hash every time) if self._compression == "gzip": with gzip.GzipFile(local_filename, 'wb', mtime=0) as gzip_file: - artifact_object.to_csv(gzip_file, **kwargs) + try: + pd_version = int(pd.__version__.split(".")[0]) + except ValueError: + pd_version = 0 + + if pd_version >= 2: + artifact_object.to_csv(gzip_file, **kwargs) + else: + # old (pandas<2) versions of pandas cannot handle direct gzip stream, so we manually encode it + artifact_object.to_csv(io.TextIOWrapper(gzip_file), **kwargs) else: artifact_object.to_csv(local_filename, compression=self._compression)