a2rl.Metadata#

class a2rl.Metadata(states, actions, rewards, forced_categories=None, frequency=None, tags=<factory>)[source]#

Bases: object

Metadata of a Whatif dataframe or dataset.

Parameters:
  • states (list[str]) – Column names for states.

  • actions (list[str]) – Column names for actions.

  • rewards (list[str]) – Column names for rewards.

  • forced_categories (Optional[list[str]]) – Numeric columns that must be interpreted as categorical or ordinal. Otherwise, column dtypes are automatically determines.

  • frequency (Optional[str]) – Sampling frequency of the dataset, in the Pandas frequency string format. See the freq argument in pandas.tseries.frequencies.to_offset(), and the pandas DateOffset tutorial. Examples: H, 2H, D.

  • tags (dict[str, Any]) – Additional custom metadata. Defaults to an empty dictionary {}.

Examples

Create an in-memory metadata object.

>>> import a2rl as wi
>>> m = wi.Metadata(
...     states=["s", "t"],
...     actions=["a"],
...     rewards=["r"],
...     frequency="H",
... )
>>> m  
Metadata(states=['s', 't'], actions=['a'], rewards=['r'], forced_categories=None,
frequency='H', tags={})

Create from a dictionary with default sampling frequency and tags.

>>> d = {
...     "states": ["s", "t"],
...     "actions": ["a"],
...     "rewards": ["r"],
... }
>>> wi.Metadata(**d)  
Metadata(states=['s', 't'], actions=['a'], rewards=['r'], forced_categories=None,
frequency=None, tags={})

Convert the metadata object to a YAML string. Please note this is shown for pedagogical purpose only. In practice, we recommend read_metadata() and save_metadata() to convert between Metadata and YAML file.

>>> from dataclasses import asdict
>>> import yaml
>>> s = yaml.safe_dump(asdict(m), sort_keys=False)
>>> print(s)
states:
- s
- t
actions:
- a
rewards:
- r
forced_categories: null
frequency: H
tags: {}

Methods