Skip to content

Commit 9b7203a

Browse files
authored
Check attribute exists using hasattr() and anchor SQLAlchemy version. (#341)
* Check attribute exists using `hasattr()` * corrected setup * formatted * formatted * remove setup.py from flake8 check * bug fix * corrected test * removed exact pinning and used <
1 parent c490d67 commit 9b7203a

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ keywords =
4949

5050
[options]
5151
install_requires =
52+
sqlalchemy<2.0.0
5253
pyparsing
5354
bioregistry
5455
click

sssom/io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def split_file(input_path: str, output_directory: Union[str, Path]) -> None:
141141

142142

143143
def _get_prefix_map(metadata: Metadata, prefix_map_mode: str = None):
144-
145144
if prefix_map_mode is None:
146145
prefix_map_mode = PREFIX_MAP_MODE_METADATA_ONLY
147146

sssom/parsers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,11 @@ def _init_mapping_set(meta: Optional[MetadataType]) -> MappingSet:
307307
def _get_mdict_ms_and_bad_attrs(
308308
row: pd.Series, ms: MappingSet, bad_attrs: Counter
309309
) -> Tuple[dict, MappingSet, Counter]:
310-
311310
mdict = {}
312311
sssom_schema_object = (
313-
SSSOMSchemaView.instance if SSSOMSchemaView.instance else SSSOMSchemaView()
312+
SSSOMSchemaView.instance
313+
if hasattr(SSSOMSchemaView, "instance")
314+
else SSSOMSchemaView()
314315
)
315316
for k, v in row.items():
316317
if v and v == v:

sssom/util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,16 @@ def assign_default_confidence(
400400
"""
401401
# Get rows having numpy.NaN as confidence
402402
if df is not None:
403-
if CONFIDENCE not in df.columns:
404-
df[CONFIDENCE] = np.NaN
405-
nan_df = pd.DataFrame(columns=df.columns)
403+
new_df = df.copy()
404+
if CONFIDENCE not in new_df.columns:
405+
new_df[CONFIDENCE] = np.NaN
406+
nan_df = pd.DataFrame(columns=new_df.columns)
406407
else:
407-
df = df[~df[CONFIDENCE].isna()]
408+
new_df = df[~df[CONFIDENCE].isna()]
408409
nan_df = df[df[CONFIDENCE].isna()]
409410
else:
410411
ValueError("DataFrame cannot be empty to 'assign_default_confidence'.")
411-
return df, nan_df
412+
return new_df, nan_df
412413

413414

414415
def remove_unmatched(df: pd.DataFrame) -> pd.DataFrame:
@@ -1496,7 +1497,6 @@ def are_params_slots(params: dict) -> bool:
14961497

14971498

14981499
def _get_sssom_schema_object() -> SSSOMSchemaView:
1499-
15001500
sssom_sv_object = (
15011501
SSSOMSchemaView.instance
15021502
if hasattr(SSSOMSchemaView, "instance")

tests/test_collapse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_collapse(self):
4444
def test_filter(self):
4545
"""Test the row count after filtering redundant rows."""
4646
df = filter_redundant_rows(self.df)
47-
self.assertEqual(len(df), 91)
47+
self.assertEqual(len(df), 92)
4848

4949
def test_ptable(self):
5050
"""Test the row count of the ptable export."""

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ description = Run code formatters and linters.
3434
[testenv:flake8]
3535
skip_install = true
3636
commands =
37-
flake8 sssom/ tests/ setup.py
37+
flake8 sssom/ tests/
3838
deps =
3939
flake8<5.0.0
4040
flake8-black

0 commit comments

Comments
 (0)