From 282c2de9c3b224bbc68af4f137b8b66fab613520 Mon Sep 17 00:00:00 2001 From: remi-sap Date: Mon, 20 Nov 2023 15:41:55 +0100 Subject: [PATCH] issue #904. Err when no props in metadata (#905) Co-authored-by: Martin Durant --- fastparquet/util.py | 6 +++++- fastparquet/writer.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fastparquet/util.py b/fastparquet/util.py index ca7fa57c..4e1c3115 100644 --- a/fastparquet/util.py +++ b/fastparquet/util.py @@ -297,7 +297,7 @@ def update_custom_metadata(obj, custom_metadata : dict): Thrift object or parquet file which metadata is to update. custom_metadata : dict Key-value metadata to update in thrift object. - + The values must be strings or binary. To pass a dictionary, serialize it as json string then encode it in binary. Notes ----- Key-value metadata are expected binary encoded. This function ensures it @@ -305,6 +305,10 @@ def update_custom_metadata(obj, custom_metadata : dict): """ kvm = (obj.key_value_metadata if isinstance(obj, ThriftObject) else obj.fmd.key_value_metadata) + + if kvm is None: + kvm = [] + # Spare list of keys. kvm_keys = [item.key for item in kvm] for key, value in custom_metadata.items(): diff --git a/fastparquet/writer.py b/fastparquet/writer.py index ca743d81..873d6954 100644 --- a/fastparquet/writer.py +++ b/fastparquet/writer.py @@ -1611,6 +1611,7 @@ def update_file_custom_metadata(path: str, custom_metadata: dict, Local path to file. custom_metadata : dict Key-value metadata to update in thrift object. + The values must be strings or binary. To pass a dictionary, serialize it as json string then encode it in binary. is_metadata_file : bool, default None Define if target file is a pure metadata file, or is a parquet data file. If `None`, is set depending file name.