DataInfo#

class pharmpy.model.DataInfo(columns=(), path=None, separator=',', missing_data_token=None, provenance=Provenance())[source]#

Bases: Sequence, Immutable

Metadata 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

dv_column

The dv column

id_column

The id column

idv_column

The idv column

missing_data_token

Token for missing data

names

All column names

path

Path of dataset file.

provenance

Provenance of dataset

separator

Separator for dataset file

symbols

Symbols for all columns

typeix

Type indexer

types

All column types

variables

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

get_dtype_dict()

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)

classmethod from_dict(d)[source]#
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

replace(**kwargs)[source]#
set_column(col)[source]#

Set ColumnInfo of an existing column of the same name

Parameters:

col (ColumnInfo) – New ColumnInfo

Returns:

DataInfo – Updated DataInfo

set_dv_column(name)[source]#
set_id_column(name)[source]#
set_idv_column(name)[source]#
set_types(value)[source]#

Set types for all columns

Parameters:

value (list or str) – Types to set. If only one this will be broadcast

Returns:

DataInfo – Updated datainfo

to_dict()[source]#
to_json(path=None)[source]#