Accept path-like objects for file inputs in PANDA and PUMA#381
Open
marouenbg wants to merge 2 commits intonetZoo:develfrom
Open
Accept path-like objects for file inputs in PANDA and PUMA#381marouenbg wants to merge 2 commits intonetZoo:develfrom
marouenbg wants to merge 2 commits intonetZoo:develfrom
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
type(x) is strchecks withisinstance(x, (str, os.PathLike))in input loading functions so thatpathlib.Pathand other path-like objects are correctly recognized as file paths.Motivation
When users pass
pathlib.Pathobjects (or otheros.PathLiketypes) as file inputs,type(x) is strreturnsFalse, causing the code to fall into the DataFrame branch and raise an error like: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()andload_expression()now useisinstance(x, (str, os.PathLike))netZooPy/panda/panda.py: PPI loading inprocessData()usesisinstancenetZooPy/puma/puma.py: miR file loading usesisinstanceTesting
Verified with toy data that the following all work:
pathlib.Pathobjectspathlib.Pathand DataFrames