Closed njzjz closed 1 month ago
The changes across the dpdata
library primarily focus on optimizing import statements to reduce the initial loading time when importing the library. This includes moving imports to within functions where they are used, restructuring conditional imports, and removing unnecessary or redundant imports. Additionally, the linting rules have been updated to enforce these changes, ensuring that module-level imports are minimized.
Files/Modules | Change Summary |
---|---|
dpdata/__init__.py |
Removed fakemodule class, adjusted lzma handling, restructured USE_RDKIT logic. |
dpdata/amber/md.py |
Moved netcdf_file import from scipy.io within the read_amber_traj function. |
dpdata/ase_calculator.py |
Added # noqa: TID253 comment to ase.calculators.calculator import for linting. |
dpdata/bond_order_system.py |
Moved Conformer import from rdkit.Chem within the to_fmt_obj method. |
dpdata/deepmd/hdf5.py |
Conditional import of h5py based on TYPE_CHECKING , local import of globfilter . |
dpdata/gaussian/gjf.py |
Reorganized imports, used try-except for openbabel , local import of csr_matrix and connected_components . |
dpdata/periodic_table.py |
Switched from monty.serialization.loadfn to json.load for loading periodic table data. |
dpdata/plugins/ase.py |
Restructured imports related to ASE modules, added necessary imports within specific functions. |
dpdata/plugins/deepmd.py |
Conditional import of h5py based on TYPE_CHECKING , local import within _from_system function. |
dpdata/plugins/rdkit.py |
Moved rdkit.Chem imports to specific methods within classes MolFormat and SdfFormat . |
dpdata/pymatgen/molecule.py |
Moved Molecule import from pymatgen.core within the to_system_data function. |
dpdata/pymatgen/structure.py |
Removed Structure import and associated try-except block. |
dpdata/rdkit/sanitize.py |
Removed openbabel import, added rdkit.Chem and BondType imports within specific functions. |
dpdata/rdkit/utils.py |
Moved Chem import from rdkit to the top of the file. |
dpdata/system.py |
Removed inheritance from MSONable , added from_dict method and related imports. |
dpdata/unit.py |
Added # noqa: TID253 comment to constants import from scipy for linting. |
pyproject.toml |
Introduced new linting rule TID253 for banned module-level imports. |
tests/test_custom_data_type.py |
Added # noqa: TID253 comment to h5py import for linting. |
tests/test_to_pymatgen_entry.py |
Added # noqa: TID253 comment to loadfn import from monty.serialization . |
Objective | Addressed | Explanation |
---|---|---|
Reduce import time by optimizing module imports (#526) | ✅ | The changes focus on moving imports to within functions and restructuring conditional imports, which minimizes the initial loading time. |
These changes effectively address the primary objective of reducing the import time for the dpdata
library, ensuring a more efficient loading process.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Comparing njzjz:move-imports
(a236787) with devel
(02309f7)
✅ 2
untouched benchmarks
Attention: Patch coverage is 80.30303%
with 13 lines
in your changes are missing coverage. Please review.
Project coverage is 83.86%. Comparing base (
02309f7
) to head (a236787
).
Files | Patch % | Lines |
---|---|---|
dpdata/rdkit/sanitize.py | 75.00% | 4 Missing :warning: |
dpdata/gaussian/gjf.py | 66.66% | 2 Missing :warning: |
dpdata/plugins/ase.py | 71.42% | 2 Missing :warning: |
dpdata/deepmd/hdf5.py | 75.00% | 1 Missing :warning: |
dpdata/plugins/deepmd.py | 85.71% | 1 Missing :warning: |
dpdata/plugins/rdkit.py | 80.00% | 1 Missing :warning: |
dpdata/rdkit/utils.py | 50.00% | 1 Missing :warning: |
dpdata/system.py | 87.50% | 1 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
For the unknown reason, the benchmark doesn't work at all...
Fix #526.
Summary by CodeRabbit
Refactor
New Features
TYPE_CHECKING
for better resource management and efficiency.from_dict
to theSystem
class for constructing instances from a data dictionary.Chores
pyproject.toml
to includeTID253
for banned module-level imports.Style
# noqa: TID253
comments to specific import statements to adhere to new linting rules and ensure clean code styling.