DataInfo#
- class pharmpy.model.DataInfo(columns=(), path=None, separator=',', missing_data_token=None, provenance=Provenance())[source]#
Bases:
Sequence,ImmutableMetadata for the dataset
Can be indexed to get ColumnInfo for the columns.
- Parameters:
columns (tuple) – Tuple of ColumnInfo
path (Path) – Path to dataset file
separator (str) – Character or regexp separator for dataset
missing_data_token (str) – Token for missing data
provenance (Provenance) – Provenance of dataset
Attributes Summary
The dv column
The id column
The idv column
Token for missing data
All column names
Path of dataset file.
Provenance of dataset
Separator for dataset file
Symbols for all columns
Type indexer
All column types
A list of all data variables in order
Methods Summary
create([columns, path, separator, ...])find_column(alias)Find a single column given a column name alias
find_column_by_property(property, value)Find a single column having a property/value pair
find_single_column_name(type[, default])Find name of single column given type
find_variable(alias)Find a single data variable given a column name alias
from_dict(d)from_json(s)Create DataInfo from JSON string
Create a dictionary from column names to pandas dtypes
read_json(path)Read DataInfo from JSON file
replace(**kwargs)set_column(col)Set ColumnInfo of an existing column of the same name
set_dv_column(name)set_id_column(name)set_idv_column(name)set_types(value)Set types for all columns
to_dict()to_json([path])Attributes Documentation
- dv_column#
The dv column
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.dv_column.name 'DV'
- id_column#
The id column
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.id_column.name 'ID'
- idv_column#
The idv column
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.idv_column.name 'TIME'
- missing_data_token#
Token for missing data
- names#
All column names
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.names ['ID', 'TIME', 'AMT', 'WGT', 'APGR', 'DV', 'FA1', 'FA2']
- path#
Path of dataset file.
If path is not None, the parsed dataset can be recreated given the path and the rest of DataInfo (including provenance).
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> str(model.datainfo.path).replace('\\', '/') '.../pharmpy/internals/example_models/pheno.dta'
- provenance#
Provenance of dataset
- separator#
Separator for dataset file
Can be a single character or a regular expression string.
- symbols#
Symbols for all columns
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.symbols [ID, TIME, AMT, WGT, APGR, DV, FA1, FA2]
- typeix#
Type indexer
Example
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.typeix['covariate'].names ['WGT', 'APGR']
- types#
All column types
- variables#
A list of all data variables in order
Methods Documentation
- classmethod create(columns=None, path=None, separator=',', missing_data_token=None, provenance=None)[source]#
- find_column(alias)[source]#
Find a single column given a column name alias
The data variable suffix of the alias will be ignored
- find_column_by_property(property, value)[source]#
Find a single column having a property/value pair
Returns None if more than one column have the pair, if no column has the pair or if not all variables of a column have the pair.
- find_single_column_name(type, default=None)[source]#
Find name of single column given type
Finds single column name with a given type, else provided default. Raises if more than one column is found or if no column is found and no default is given.
- Parameters:
type (str) – Column type
default (Optional[str]) – Default if column type is not found
- Returns:
str – Name of column
- find_variable(alias)[source]#
Find a single data variable given a column name alias
The alias can be the name of the column (e.g. “DV”) if it maps to one single data variable or the name of the column suffixed by “:” and the DVID number if it maps to multiple data variables (e.g. “DV:1” meaning the DV column where DVID is 1)
- static from_json(s)[source]#
Create DataInfo from JSON string
- Parameters:
s (str) – JSON string
- Returns:
DataInfo – Created DataInfo object
- get_dtype_dict()[source]#
Create a dictionary from column names to pandas dtypes
This can be used as input to some pandas functions to convert column to the correct pandas dtype.
- Returns:
dict – Column name to pandas dtype
Examples
>>> from pharmpy.modeling import * >>> model = load_example_model("pheno") >>> model.datainfo.get_dtype_dict() {'ID': 'int32', 'TIME': 'float64', 'AMT': 'float64', 'WGT': 'float64', 'APGR': 'float64', 'DV': 'float64', 'FA1': 'float64', 'FA2': 'float64'}
- static read_json(path)[source]#
Read DataInfo from JSON file
- Parameters:
path (Path or str) – Path to JSON datainfo file
- Returns:
DataInfo – Created DataInfo object
- set_column(col)[source]#
Set ColumnInfo of an existing column of the same name
- Parameters:
col (ColumnInfo) – New ColumnInfo
- Returns:
DataInfo – Updated DataInfo