Data

Bundled dataset loaders

openpkpd.data.load_theophylline()[source]

Load the 12-subject Boeckmann theophylline dataset.

Return type:

NONMEMDataset

Returns:

NONMEMDataset with columns ID, TIME, AMT, DV, EVID, MDV, WT. 144 rows (12 dose events + 132 observations, 12 subjects × 11 timepoints).

openpkpd.data.load_warfarin()[source]

Load the warfarin PK dataset.

Return type:

NONMEMDataset

NONMEMDataset

class openpkpd.data.dataset.NONMEMDataset(df, source_path=None, ignore_char=None, column_map=<factory>)[source]

Bases: object

A validated, preprocessed NONMEM dataset.

After construction:
  • All columns are renamed to NONMEM standard names

  • Missing numeric values (-99 or user-specified) replaced with NaN

  • EVID column added (default 0 = observation) if absent

  • MDV column added based on EVID if absent

  • CMT column added (default 1) if absent

  • Rows sorted by ID, then TIME

Parameters:
df: DataFrame
source_path: str | None = None
ignore_char: str | None = None
column_map: dict[str, str]
classmethod from_csv(path, input_columns=None, ignore_char=None, missing_value=-99.0, sep=',', impute_covariates=None, impute_method='locf')[source]

Load a NONMEM dataset from a CSV file.

Parameters:
  • path (str) – Path to CSV file.

  • input_columns (list[str] | None) – Ordered list of standard column names (from $INPUT). If None, treat first row as header.

  • ignore_char (str | None) – Ignore lines where the first data character matches this.

  • missing_value (float) – Numeric value treated as missing (default -99).

  • sep (str) – Column separator (default comma; use r’s+’ for whitespace).

  • impute_covariates (list[str] | None) – Column names to impute after loading. When None (default) no imputation is performed.

  • impute_method (str) – Imputation strategy passed to CovariateImputer: 'locf' (default), 'nocb', 'mean', 'median', or 'knn'.

Return type:

NONMEMDataset

classmethod from_dataframe(df, missing_value=-99.0, impute_covariates=None, impute_method='locf')[source]

Construct from an already-loaded pandas DataFrame.

Parameters:
  • df (DataFrame) – Input DataFrame.

  • missing_value (float) – Numeric sentinel for missing values (default -99).

  • impute_covariates (list[str] | None) – Column names to impute after preprocessing. When None (default) no imputation is performed.

  • impute_method (str) – Imputation strategy: 'locf' (default), 'nocb', 'mean', 'median', or 'knn'.

Return type:

NONMEMDataset

subject_ids()[source]

Return sorted list of unique subject IDs.

Return type:

list[int]

subject_data(subject_id)[source]

Return all rows for a single subject.

Return type:

DataFrame

Parameters:

subject_id (int)

observation_rows(subject_id=None)[source]

Return observation rows (EVID=0, MDV=0).

Return type:

DataFrame

Parameters:

subject_id (int | None)

n_subjects()[source]
Return type:

int

n_observations()[source]
Return type:

int

property has_lloq: bool

Return True if an LLOQ column is present in the dataset.

The LLOQ column must exist and contain at least one non-NaN value for this property to return True.

lloq_values(subject_id=None)[source]

Return LLOQ values for the dataset or a single subject.

Only observation rows (EVID=0, MDV=0) are returned. If no LLOQ column is present, an array of NaN is returned with the same length as the observation rows.

Parameters:

subject_id (int | None) – If provided, return LLOQ values only for this subject. If None, return values for all subjects.

Return type:

ndarray

Returns:

NumPy array of LLOQ values, shape (n_obs_rows,).

impute_covariates(columns, method='locf')[source]

Return a new NONMEMDataset with missing covariate values imputed.

Parameters:
  • columns (list[str]) – Column names to impute.

  • method (str) – Strategy passed to CovariateImputer: 'mean', 'median', 'locf' (default), 'nocb', or 'knn'.

Return type:

NONMEMDataset

Returns:

New NONMEMDataset; original is unchanged.

__init__(df, source_path=None, ignore_char=None, column_map=<factory>)
Parameters:
Return type:

None