CallbackData¶
- class passengersim.callbacks.base.CallbackData[source]¶
Bases:
MutableMappingData collected during callbacks.
Methods
__init__()clear()get(k[,d])get_data(label, trial, sample[, days_prior])Return the row dictionary for one trial, sample and day, creating it if needed.
items()keys()pop(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem()as a 2-tuple; but raise KeyError if D is empty.
setdefault(k[,d])to_dataframe(item)update([E, ]**F)If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
update_data(label, trial, sample[, days_prior])Add keyword values to a callback row.
update_data_from_mapping(label, trial, sample)Add values to the row for one trial, sample and day.
values()-
get_data(label: str, trial: int, sample: int, days_prior: int | None =
None) dict[str, Any][source]¶ Return the row dictionary for one trial, sample and day, creating it if needed.
Rows under a label are appended in order, and only the most recent row is reused: a row is matched on its
trial,sampleand (when given)days_priorindex keys, and a new row is started when they differ.- Parameters:
- Returns:
dict – The stored row, which holds the index keys and any values added to it.
-
update_data(label: str, trial: int, sample: int, days_prior: int | None =
None, **kwargs: Any) None[source]¶ Add keyword values to a callback row.
- Parameters:
- label : str¶
Callback result key.
- trial : int¶
Trial and sample identifying the row.
- sample : int¶
Trial and sample identifying the row.
- days_prior : int, optional¶
Days before departure for a daily observation.
- **kwargs: Any¶
Values to add. Use update_data_from_mapping for a value named ``label`, which is also an argument to this method.
-
update_data_from_mapping(label: str, trial: int, sample: int, days_prior: int | None =
None, values: Mapping[str, Any] | None =None, /, **kwargs: Any) None[source]¶ Add values to the row for one trial, sample and day.
All the bookkeeping parameters are positional-only, so a value may be given as a keyword of any name, including
labelorvalues. Values may also be given as avaluesmapping, which is how the dictionary returned by a callback is stored; keyword values are applied after it.The keys
trial,sampleanddays_priorare reserved for the row’s own index, whichget_data()matches rows on, so a value under one of those keys is refused rather than stored. This applies to every row, daily or not.- Parameters:
- label : str¶
The
callback_datakey: a hook name, or a callback’s result name.- trial : int¶
The trial and sample the row belongs to.
- sample : int¶
The trial and sample the row belongs to.
- days_prior : int, optional¶
The days prior to departure, for a daily callback’s row.
- values : Mapping, optional¶
Values to store in the row.
- **kwargs: Any¶
More values to store in the row.
- Raises:
ValueError – If a value is given under
trial,sampleordays_prior.
- clear() None. Remove all items from D.¶
- items() a set-like object providing a view on D's items¶
- keys() a set-like object providing a view on D's keys¶
- pop(k[, d]) v, remove specified key and return the corresponding value.¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair¶
as a 2-tuple; but raise KeyError if D is empty.
- update([E, ]**F) None. Update D from mapping/iterable E and F.¶
If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values¶
-
get_data(label: str, trial: int, sample: int, days_prior: int | None =