From 62e7cba278dfcbbd78cdd1026d92ba0b3bf9eedb Mon Sep 17 00:00:00 2001 From: Adrien Berchet Date: Tue, 10 Sep 2024 08:20:56 +0200 Subject: [PATCH] Fix: Deduplicate entries according to the (name, mtype, layer) triplet (#133) --- .pre-commit-config.yaml | 4 ++-- morph_tool/morphdb.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f70b6e7..a10e3d9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/codespell-project/codespell - rev: v2.1.0 + rev: v2.3.0 hooks: - id: codespell - repo: https://github.com/PyCQA/pydocstyle @@ -22,7 +22,7 @@ repos: - id: pydocstyle exclude: ^(functional_tests|tests|doc|examples|setup.py) - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 5.0.4 hooks: - id: flake8 exclude: ^(functional_tests|tests|doc) diff --git a/morph_tool/morphdb.py b/morph_tool/morphdb.py index 42d4d3f..963d44b 100644 --- a/morph_tool/morphdb.py +++ b/morph_tool/morphdb.py @@ -264,7 +264,7 @@ def from_folder(cls, Args: morphology_folder: a folder containing morphologies mtypes: a sequence of 2-tuples (morphology name, mtype) - label: (optional) a group label to be used to identify the morphlogies from this folder + label: (optional) a group label to be used to identify the morphologies from this folder extension: Specify the morphology format to consider, if the folder contains multiple formats @@ -373,7 +373,10 @@ def __add__(self, other): def __iadd__(self, other): """Overloaded method.""" if isinstance(other, MorphDB): - self.df = pd.concat([self.df, other.df]).drop_duplicates() + self.df = pd.concat( + [self.df, other.df], + ignore_index=True, + ).drop_duplicates(["name", "mtype", "layer"]) MorphDB._sanitize_df_types(self.df) else: raise TypeError(f'Must be MorphDB or a sequence of MorphInfo, not {type(other)}')