From 7ca7e68c90d538e3c208bb3579a873f58da6538e Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 14 Sep 2023 17:18:33 -0400 Subject: [PATCH] drop the old data type with the same name and throw warning --- dpdata/system.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dpdata/system.py b/dpdata/system.py index 8af8e4a5..65e0a39f 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -1,6 +1,7 @@ # %% import glob import os +import warning from copy import deepcopy from typing import Any, Dict, Optional, Tuple, Union @@ -963,7 +964,13 @@ def register_data_type(cls, *data_type: Tuple[DataType]): *data_type : tuple[DataType] data type to be regiestered """ - cls.DTYPES = cls.DTYPES + tuple(data_type) + all_dtypes = cls.DTYPES + tuple(data_type) + dtypes_dict = {} + for dt in all_dtypes: + if dt.name in dtypes_dict: + warnings.warn(f"Data type {dt.name} is registered twice; only the newly registered one will be used.", UserWarning) + dtypes_dict[dt.name] = dt + cls.DTYPES = tuple(dtypes_dict.values()) def get_cell_perturb_matrix(cell_pert_fraction):