btrdb.transformers#

A number of transformation and serialization functions have been developed so you can use the data in the format of your choice. These functions are provided in the StreamSet class.

Value transformation utilities

btrdb.transformers.arrow_to_dict(streamset, agg=None, name_callable=None)#

Returns a list of dicts for each time code with the appropriate stream data attached.

Parameters:
  • agg (List[str], default: ["mean"]) – Specify the StatPoint field or fields (e.g. aggregating function) to constrain dict keys. Must be one or more of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object.

Notes

This method is available for commercial customers with arrow-enabled servers.

btrdb.transformers.arrow_to_numpy(streamset, agg=None)#

Return a multidimensional array in the numpy format.

Parameters:

agg (List[str], default: ["mean"]) – Specify the StatPoint field or fields (e.g. aggregating function) to return for the arrays. Must be one or more of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.

Notes

This method first converts to a pandas data frame then to a numpy array.

This method is available for commercial customers with arrow-enabled servers.

btrdb.transformers.arrow_to_series(streamset, agg='mean', name_callable=None)#

Returns a list of Pandas Series objects indexed by time

Parameters:
  • agg (List[str], default: ["mean"]) – Specify the StatPoint field or fields (e.g. aggregating function) to create the Series from. Must be one or more of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object.

Notes

This method is available for commercial customers with arrow-enabled servers.

btrdb.transformers.arrow_to_dataframe(streamset, columns=None, agg=None, name_callable=None) DataFrame#

Returns a Pandas DataFrame object indexed by time and using the values of a stream for each column.

Parameters:
  • columns (sequence) – column names to use for DataFrame. Deprecated and not compatible with name_callable.

  • agg (List[str], default: ["mean"]) – Specify the StatPoint fields (e.g. aggregating function) to create the dataframe from. Must be one or more of “min”, “mean”, “max”, “count”, “stddev”, or “all”. This argument is ignored if not using StatPoints.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object.

Notes

This method is available for commercial customers with arrow-enabled servers.

btrdb.transformers.arrow_to_polars(streamset, agg=None, name_callable=None)#

Returns a Polars DataFrame object with time as a column and the values of a stream for each additional column from an arrow table.

Parameters:
  • agg (List[str], default: ["mean"]) – Specify the StatPoint field or fields (e.g. aggregating function) to create the dataframe from. Must be one or multiple of “min”, “mean”, “max”, “count”, “stddev”, or “all”. This argument is ignored if not using StatPoints.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object.

Notes

This method is available for commercial customers with arrow-enabled servers.

btrdb.transformers.arrow_to_arrow_table(streamset)#

Return a pyarrow table of data.

Notes

This method is available for commercial customers with arrow-enabled servers.

btrdb.transformers.to_dict(streamset, agg='mean', name_callable=None)#

Returns a list of OrderedDict for each time code with the appropriate stream data attached.

Parameters:
  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to constrain dict keys. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object.

btrdb.transformers.to_array(streamset, agg='mean')#

Returns a multidimensional numpy array (similar to a list of lists) containing point classes.

Parameters:

agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to return for the arrays. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.

btrdb.transformers.to_polars(streamset, agg='mean', name_callable=None)#

Returns a Polars DataFrame object with time as a column and the values of a stream for each additional column.

Parameters:
  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to create the Series from. Must be one of “min”, “mean”, “max”, “count”, “stddev”, or “all”. This argument is ignored if not using StatPoints.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object. This is not compatible with agg == “all” at this time

btrdb.transformers.to_series(streamset, datetime64_index=True, agg='mean', name_callable=None)#

Returns a list of Pandas Series objects indexed by time

Parameters:
  • datetime64_index (bool) – Directs function to convert Series index to np.datetime64[ns] or leave as np.int64.

  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to create the Series from. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object.

btrdb.transformers.to_dataframe(streamset, columns=None, agg='mean', name_callable=None)#

Returns a Pandas DataFrame object indexed by time and using the values of a stream for each column.

Parameters:
  • columns (sequence) – column names to use for DataFrame. Deprecated and not compatible with name_callable.

  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to create the Series from. Must be one of “min”, “mean”, “max”, “count”, “stddev”, or “all”. This argument is ignored if not using StatPoints.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object. This is not compatible with agg == “all” at this time

btrdb.transformers.to_csv(streamset, fobj, dialect=None, fieldnames=None, agg='mean', name_callable=None)#

Saves stream data as a CSV file.

Parameters:
  • fobj (str or file-like object) – Path to use for saving CSV file or a file-like object to use to write to.

  • dialect (csv.Dialect) – CSV dialect object from Python csv module. See Python’s csv module for more information.

  • fieldnames (sequence) – A sequence of strings to use as fieldnames in the CSV header. See Python’s csv module for more information.

  • agg (str, default: "mean") – Specify the StatPoint field (e.g. aggregating function) to return when limiting results. Must be one of “min”, “mean”, “max”, “count”, or “stddev”. This argument is ignored if RawPoint values are passed into the function.

  • name_callable (lambda, default: lambda s: s.collection + "/" + s.name) – Specify a callable that can be used to determine the series name given a Stream object.