Skip to main content

PyRecords

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: Records

Implementations§

§

impl PyRecords

pub(crate) fn new(inner: impl Into<Records>) -> Self

This table from the core’s own record set.

fn column(&self, name: &str) -> Option<&Column>

The column named name, if the table holds one.

§

impl PyRecords

fn columns(&self) -> Vec<&'static str>

The column names, in the order the producing frame wrote them.

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

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>

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>

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

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

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>>

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>

The table as a list of row tuples, each in column order.

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>

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<()>

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 Clone for PyRecords

§

fn clone(&self) -> PyRecords

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl DerefToPyAny for PyRecords

§

impl IntoPy<Py<PyAny>> for PyRecords

§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
§

impl PyClass for PyRecords

§

type Frozen = True

Whether the pyclass is frozen. Read more
§

impl PyClassImpl for PyRecords

§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
§

type BaseType = PyAny

Base class
§

type ThreadChecker = SendablePyClass<PyRecords>

This handles following two situations: Read more
§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild

Immutable or mutable
§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
§

fn items_iter() -> PyClassItemsIter

§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

§

fn dict_offset() -> Option<isize>

§

fn weaklist_offset() -> Option<isize>

§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a PyRecords

§

type Holder = Option<PyRef<'py, PyRecords>>

§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

§

impl PyMethods<PyRecords> for PyClassImplCollector<PyRecords>

§

fn py_methods(self) -> &'static PyClassItems

§

impl PyTypeInfo for PyRecords

§

const NAME: &'static str = "Records"

Class name.
§

const MODULE: Option<&'static str>

Module name, if any.
§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
§

fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
§

fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
§

fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromPyObject<'_> for T
where T: PyClass + Clone,

§

fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

§

const NAME: &'static str = <T as PyTypeInfo>::NAME

Name of self. This is used in error messages, for example.
§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,