iprPy.record package
Module contents
- class Record(model: str | IOBase | DataModelDict | None = None, name: str | None = None, database=None, **kwargs: any)
Bases:
object
Class for handling different record styles in the same fashion. The base class defines the common methods and attributes.
- cdcsquery(**kwargs: any) dict
Builds a CDCS-style query based on kwargs values for the record style.
- Parameters:
**kwargs (any) – Any of the record style-specific search parameters.
- Returns:
The CDCS-style query
- Return type:
- get_file(filename: str | Path, localroot: str | Path | None = None)
Retrieves a file either locally or from the record’s tar archive.
- Parameters:
filename (str or Path) – The name/path for the file. For local files, this is taken relative to localroot. For files in the tar archive, this is taken relative to the tar’s root directory which is always named for the record, i.e., {self.name}/{filename}.
localroot (str, Path or None, optional) – The local root directory that filename (if it exists) is relative to. The default value of None will use the current working directory.
- Raises:
ValueError – If filename exists in the tar but is not a file.
- Returns:
A file-like object in binary read mode that allows for the file contents to be read.
- Return type:
- load_model(model: str | IOBase | DataModelDict, name: str | None = None)
Loads record contents from a given model.
- metadata() dict
Generates a dict of simple metadata values associated with the record. Useful for quickly comparing records and for building pandas.DataFrames for multiple records of the same style.
- mongoquery(name: str | list | None = None, **kwargs: any) dict
Builds a Mongo-style query based on kwargs values for the record style.
- pandasfilter(dataframe: DataFrame, name: str | list | None = None, **kwargs: any) Series
Filters a pandas.DataFrame based on kwargs values for the record style.
- Parameters:
- Returns:
Boolean map of matching values
- Return type:
pandas.Series
- reload_model()
Reloads the record based on the model content. This allows for direct changes to the model to be updated to the object.
- set_values(name: str | None = None)
Set multiple object attributes at the same time.
- Parameters:
name (str, optional) – The name to assign to the record. Often inferred from other attributes if not given.
- load_record(style: str, model: str | DataModelDict | None = None, name: str | None = None, database=None, **kwargs) Record
Loads a Record subclass associated with a given record style.
- Parameters:
style (str) – The record style.
name (str, optional) – The name to give to the specific record.
model (str, DataModelDict, optional) – Data model content to load for the given record style.
database (yabadaba.Database, optional) – Allows for a default database to be associated with the record.
**kwargs (any) – Any extra keyword parameter supported by the record style.
- Returns:
A Record object for the style
- Return type:
subclass of Record