Struct PyRecords
pub struct PyRecords {
inner: Records,
}Expand description
A table of results: named columns of equal length, each carrying its kind.
Returned by every reading taken against market data — a valuation, a calibration, a fit, an attribution. A listing read off passive contract terms with no market in hand stays a list of tuples.
Fields§
§inner: RecordsImplementations§
§impl PyRecords
impl PyRecords
fn columns(&self) -> Vec<&'static str>
fn columns(&self) -> Vec<&'static str>
The column names, in the order the producing frame wrote them.
fn column_kinds(&self) -> Vec<&'static str>
fn column_kinds(&self) -> Vec<&'static str>
Each column’s kind — "text", "number" or "date" — in column order.
What a caller building their own frame needs, and what the two dataframe readings declare their schema from.
fn __len__(&self) -> usize
fn __len__(&self) -> usize
How many rows the table holds.
Rows, while [...] takes a column name — the two axes the table has,
and the pair that makes for row in records ambiguous. See
__iter__, which refuses it rather than choosing.
fn __getitem__(
&self,
py: Python<'_>,
key: &Bound<'_, PyAny>,
) -> PyResult<PyObject>
fn __getitem__( &self, py: Python<'_>, key: &Bound<'_, PyAny>, ) -> PyResult<PyObject>
One column’s values, by name.
The key is taken as &Bound<PyAny> rather than &str so that an index
of the wrong type is refused here. Left to the extractor it came back
as “argument ‘name’: ‘int’ object cannot be converted to ‘PyString’”,
which names neither the type being indexed nor the thing to do instead
— and which is what a caller writing for row in records actually saw,
because the sequence protocol reaches this with 0.
fn __iter__(&self) -> PyResult<PyObject>
fn __iter__(&self) -> PyResult<PyObject>
Refused, and deliberately.
A table has two axes and the name says nothing about which one a loop wants. The two dataframe libraries a caller is likely to arrive from do not agree either — pandas iterates column names, polars iterates columns — so any choice here silently surprises half of them.
Without this the loop still failed, because __len__ made the sequence
protocol apply and it reached __getitem__ with 0. It failed with a
message about converting an int to a PyString, which sent at least
one reader looking for a string they had passed wrongly. This says what
to call instead.
fn __repr__(&self) -> String
fn __str__(&self) -> String
fn __str__(&self) -> String
The table rendered for reading: a header, a rule, one line per row.
print(records) is the whole of the reading a caller at a prompt
wants, so it needs no method. Text and dates sit left, numbers right
with thousands separators; a numeric column prints two decimals when
its largest magnitude is at least a thousand and six otherwise, so
money reads as money and a rate or a discount factor keeps its digits.
repr stays the one-line summary, which is what a traceback or a list
of tables can bear.
fn _repr_html_(&self) -> String
fn _repr_html_(&self) -> String
The table as HTML, which is what a notebook shows for a cell whose
value is a Records: the same cells str prints, numbers sitting
right, text escaped, captioned with the row count.
fn to_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>>
fn to_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>>
The table as a mapping of column name to list of values.
Text becomes str, Number float, and Date datetime.date with
None where a row has none. An absent number is nan, not None:
the cell belongs to a numeric column and keeping it numeric is what
stops the column changing type around it.
fn to_rows<'py>(&self, py: Python<'py>) -> Bound<'py, PyList>
fn to_rows<'py>(&self, py: Python<'py>) -> Bound<'py, PyList>
The table as a list of row tuples, each in column order.
fn to_polars(&self, py: Python<'_>) -> PyResult<PyObject>
fn to_polars(&self, py: Python<'_>) -> PyResult<PyObject>
The table as a polars.DataFrame, built with a declared schema.
§Errors
ImportError naming the helixio[polars] extra when polars is absent.
fn to_pandas(&self, py: Python<'_>) -> PyResult<PyObject>
fn to_pandas(&self, py: Python<'_>) -> PyResult<PyObject>
The table as a pandas.DataFrame, with declared dtypes.
A date column becomes datetime64[ns] with NaT where absent, rather
than the object column pandas infers from datetime.date values.
§Errors
ImportError naming the helixio[pandas] extra when pandas is absent.
fn to_csv(&self, path: &str) -> PyResult<()>
fn to_csv(&self, path: &str) -> PyResult<()>
Writes the table to path as CSV — a header row, then one line per row.
Imports nothing. Writing a text format through a dataframe library
would make a plain to_csv the one call in this package that needs a
dependency, which is what this avoids.
§Errors
OSError if the file cannot be written.
Trait Implementations§
impl DerefToPyAny for PyRecords
§impl PyClassImpl for PyRecords
impl PyClassImpl for PyRecords
§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
§type ThreadChecker = SendablePyClass<PyRecords>
type ThreadChecker = SendablePyClass<PyRecords>
§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
§impl PyMethods<PyRecords> for PyClassImplCollector<PyRecords>
impl PyMethods<PyRecords> for PyClassImplCollector<PyRecords>
fn py_methods(self) -> &'static PyClassItems
§impl PyTypeInfo for PyRecords
impl PyTypeInfo for PyRecords
§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.