Skip to content

Commit

Permalink
drop the old data type with the same name and throw warning
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz authored Sep 14, 2023
1 parent b45911a commit 7ca7e68
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dpdata/system.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# %%
import glob
import os
import warning
from copy import deepcopy
from typing import Any, Dict, Optional, Tuple, Union

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 7ca7e68

Please sign in to comment.