Skip to content

Accept path-like objects for file inputs in PANDA and PUMA#381

Open
marouenbg wants to merge 2 commits intonetZoo:develfrom
marouenbg:fix/mixed-path-dataframe-inputs
Open

Accept path-like objects for file inputs in PANDA and PUMA#381
marouenbg wants to merge 2 commits intonetZoo:develfrom
marouenbg:fix/mixed-path-dataframe-inputs

Conversation

@marouenbg
Copy link
Contributor

Summary

Replace type(x) is str checks with isinstance(x, (str, os.PathLike)) in input loading functions so that pathlib.Path and other path-like objects are correctly recognized as file paths.

Motivation

When users pass pathlib.Path objects (or other os.PathLike types) as file inputs, type(x) is str returns False, causing the code to fall into the DataFrame branch and raise an error like:

Exception: Please provide a pandas dataframe for motif data with column names as 'source', 'target', and 'weight'.

This also prevented mixing file paths and DataFrames for different inputs (e.g., PPI as a path and expression as a DataFrame).

Fixes #351

Changes

  • netZooPy/panda/io.py: load_motif() and load_expression() now use isinstance(x, (str, os.PathLike))
  • netZooPy/panda/panda.py: PPI loading in processData() uses isinstance
  • netZooPy/puma/puma.py: miR file loading uses isinstance

Testing

Verified with toy data that the following all work:

  • All paths (str) - baseline
  • All DataFrames
  • Mixed: expr=DataFrame + motif/ppi=path
  • Mixed: motif=DataFrame + expr/ppi=path
  • Mixed: ppi=DataFrame + expr/motif=path
  • All pathlib.Path objects
  • Mixed pathlib.Path and DataFrames

Replace 'type(x) is str' checks with 'isinstance(x, (str, os.PathLike))'
so that pathlib.Path and other path-like objects are correctly recognized
as file paths instead of being rejected as invalid DataFrames.

This fixes the inability to mix file paths and DataFrames as inputs,
which failed when path-like objects (e.g. pathlib.Path) were used.

Files changed:
- netZooPy/panda/io.py: load_motif() and load_expression()
- netZooPy/panda/panda.py: PPI loading in processData()
- netZooPy/puma/puma.py: miR file loading

Fixes netZoo#351
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.51%. Comparing base (b6d05b7) to head (0964f65).
⚠️ Report is 47 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #381      +/-   ##
==========================================
+ Coverage   57.06%   59.51%   +2.44%     
==========================================
  Files          39       45       +6     
  Lines        2518     3053     +535     
==========================================
+ Hits         1437     1817     +380     
- Misses       1081     1236     +155     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- test_cobra: use numpy array for mean computation instead of pandas
  Series integer access (KeyError: 0 with string column index)
- condor: use .iloc for positional access on iterrows() Series
  (KeyError: 2 with string column labels)
- condor: use ki.sum() instead of float(sum(ki)) to avoid TypeError
  with np.matrix column vectors in newer numpy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant