API¶
pyodc¶
Functions¶
- pyodc.encode_odb(dataframe: DataFrame, target, rows_per_frame=10000, types: Optional[dict] = None, bigendian: bool = False, properties: Optional[dict] = None, bitfields: Optional[dict] = None)
Encode a pandas dataframe into an ODB-2 stream
- Parameters
dataframe (DataFrame) – A pandas dataframe to encode
target (str|file) – A file-like object to write the encoded data to
types (dict) – A dictionary of (optional) column-name : constant
DataType
pairs, orNone
bigendian (bool) – Encode in big-endian byte order if
True
properties (dict) – Encode a dictionary of supplied properties
bitfields (dict) – A dictionary containing entries for BITFIELD columns. The values are either bitfield names, or tuple pairs of bitfield name and bitfield size
- pyodc.read_odb(source, columns=None, aggregated=True, single=False)
Decode an ODB-2 stream into a pandas dataframe
- Parameters
source (str|file) – A file-like object to decode the data from
columns (list|tuple) – A list or a tuple of columns to decode
aggregated (bool) – Group result into logical dataframes if
True
single (bool) – Group result into a single dataframe if
True
and possible
- Returns
DataFrame
Classes¶
- class pyodc.DataType(value)
Defines the encoded data type for a specified column
- IGNORE = 0
Ignore value
- INTEGER = 1
Integer value
- REAL = 2
Real value
- STRING = 3
String value
- BITFIELD = 4
Bitfield value
- DOUBLE = 5
Double value
- class pyodc.ColumnInfo(name, idx, dtype, datasize, bitfields)
Represent the type of a column in the encoded file
- Parameters
name (str) – The name of the column
idx (int) – The index of the column
dtype (DataType) – The type of the column as
DataType
datasize (int) – The size of the column
bitfields (iter) – For columns of bitfield type, define
Bitfield
specification
- name
The name of the column
- Type
str
- idx
The index of the column
- Type
int
- dtype
The type of the column as
DataType
- Type
DataType
- datasize
The size of the column
- Type
int
- bitfields
For columns of bitfield type, define
Bitfield
specification- Type
iter
- class Bitfield(name, size, offset)
Specifies the meaning of the bits encoded in a column of type bitfield
- Parameters
name (str) – Name of a group of bits
size (int) – Number of bits
offset (int) – Offset of bits within the decoded (integer) value
- name
Name of a group of bits
- Type
str
- size
Number of bits
- Type
int
- offset
Offset of bits within the decoded (integer) value
- Type
int
- class pyodc.Frame(source)
Represent the decoded dataframe
- Parameters
source (str|file) – A file-like object to decode the data from
- properties
Dictionary of additional properties that can contain arbitrary metadata
- Type
dict
- columns
A list of
ColumnInfo
objects describing the column structure of the frame- Type
list
- nrows
Number of rows of data within the frame
- Type
int
- ncolumns
Number of data columns within the frame
- Type
int
- dataframe(columns=None)
Decodes the frame into a pandas dataframe
- Parameters
columns – List of columns to decode
- Returns
DataFrame
- class pyodc.Reader(source, aggregated=True)
An object that owns the input data stream, and splits it into a sequence of frames that can be interrogated
- Parameters
source (str|file) – A file-like object to decode the data from
aggregated (bool) – Group result into logical dataframes if
True
- frames
Decoded dataframes
- Type
DataFrame