Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace the old data type with the same name and throw warning #541

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 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 warnings
from copy import deepcopy
from typing import Any, Dict, Optional, Tuple, Union

Expand Down Expand Up @@ -963,7 +964,16 @@
*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(

Check warning on line 971 in dpdata/system.py

View check run for this annotation

Codecov / codecov/patch

dpdata/system.py#L971

Added line #L971 was not covered by tests
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
Loading