Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

WIP: Allow DataFrames as inputs. #127

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions afqinsight/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ def load_afq_data(
--------
transform.AFQDataFrameMapper
"""
nodes = pd.read_csv(
fn_nodes, converters={"subjectID": str, "nodeID": int, "tractID": str}
)
if isinstance(fn_nodes, pd.DataFrame):
nodes = fn_nodes
else:
nodes = pd.read_csv(
fn_nodes, converters={"subjectID": str, "nodeID": int, "tractID": str}
)
unnamed_cols = [col for col in nodes.columns if "Unnamed:" in col]
nodes.drop(unnamed_cols, axis="columns", inplace=True)

Expand Down Expand Up @@ -269,15 +272,17 @@ def load_afq_data(
"load data for an unsupervised learning "
"problem, please set `unsupervised=True`."
)

# Read using sep=None, engine="python" to allow for both csv and tsv
targets = pd.read_csv(
fn_subjects,
sep=None,
engine="python",
index_col=index_col,
converters={index_col: str},
)
if isinstance(fn_subjects, pd.DataFrame):
targets = fn_subjects
else:
# Read using sep=None, engine="python" to allow for both csv and tsv
targets = pd.read_csv(
fn_subjects,
sep=None,
engine="python",
index_col=index_col,
converters={index_col: str},
)

# Drop unnamed columns
unnamed_cols = [col for col in targets.columns if "Unnamed:" in col]
Expand Down