DataInfo#

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

Bases: Sequence, Immutable

Metadata for the dataset

Can be indexed to get ColumnInfo for the columns.

Parameters:
  • columns (list) – List of column names

  • path (Path) – Path to dataset file

  • separator (str) – Character or regexp separator for dataset

  • missing_data_token (str) – Token for missing data

Attributes Summary

descriptorix

Descriptor indexer

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

separator

Separator for dataset file

symbols

Symbols for all columns

typeix

Type indexer

types

All column types

Methods Summary

create([columns, path, separator, ...])

find_single_column_name(type[, default])

Find name of single column given type

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

descriptorix#

Descriptor indexer

Example

>>> from pharmpy.modeling import load_example_model
>>> model = load_example_model("pheno")
>>> model.datainfo.descriptorix['body weight'].names
['WGT']
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

Examples

>>> from pharmpy.modeling import load_example_model
>>> model = load_example_model("pheno")
>>> str(model.datainfo.path).replace('\\', '/')
'.../pharmpy/internals/example_models/pheno.dta'
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

Methods Documentation

classmethod create(columns=None, path=None, separator=',', missing_data_token=None)[source]#
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

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]#