Struct perspective_python::Table
source · pub struct Table(/* private fields */);
Expand description
Table
is Perspective’s columnar data frame, analogous to a Pandas
DataFrame
or Apache Arrow, supporting append & in-place updates, removal by
index, and update notifications.
A Table
contains columns, each of which have a unique name, are strongly and
consistently typed, and contains rows of data conforming to the column’s type.
Each column in a Table
must have the same number of rows, though not every
row must contain data; null-values are used to indicate missing values in the
dataset.
The schema of a Table
is immutable after creation, which means the column
names and data types cannot be changed after the Table
has been created.
Columns cannot be added or deleted after creation either, but a View
can be
used to select an arbitrary set of columns from the Table
.
perspective
docs for the Rust API.
perspective
docs for the Rust API.
Implementations§
source§impl Table
impl Table
sourcepub fn get_index(&self) -> Option<String>
pub fn get_index(&self) -> Option<String>
Returns the name of the index column for the table.
§JavaScript Examples
const table = await client.table("x,y\n1,2\n3,4", { index: "x" });
const index = table.get_index(); // "x"
§Python Examples
table = client.table("x,y\n1,2\n3,4", index="x");
index = table.get_index() # "x"
§Examples
let options = TableInitOptions {index: Some("x".to_string()), ..default() };
let table = client.table("x,y\n1,2\n3,4", options).await;
let tables = client.open_table("table_one").await;
pub fn get_name(&self) -> String
sourcepub fn clear(&self) -> PyResult<()>
pub fn clear(&self) -> PyResult<()>
Removes all the rows in the Table
, but preserves everything else including
the schema, index, and any callbacks or registered View
instances.
Calling Table::clear
, like Table::update
and Table::remove
, will
trigger an update event to any registered listeners via View::on_update
.
sourcepub fn delete(&self) -> PyResult<()>
pub fn delete(&self) -> PyResult<()>
Delete this Table
and cleans up associated resources, assuming it has no
View
instances registered to it (which must be deleted first).
Table
s do not stop consuming resources or processing updates when they are
garbage collected in their host language - you must call this method to reclaim
these.
§JavaScript Examples
const table = await client.table("x,y\n1,2\n3,4");
// ...
await table.delete();
§Python Examples
table = client.table("x,y\n1,2\n3,4")
// ...
table.delete()
§Examples
let opts = TableInitOptions::default();
let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
let table = client.table(data, opts).await?;
// ...
table.delete().await?;
sourcepub fn make_port(&self) -> PyResult<i32>
pub fn make_port(&self) -> PyResult<i32>
Create a unique channel ID on this Table
, which allows View::on_update
callback calls to be associated with the Table::update
which caused them.
sourcepub fn on_delete(&self, callback: Py<PyAny>) -> PyResult<u32>
pub fn on_delete(&self, callback: Py<PyAny>) -> PyResult<u32>
Register a callback which is called exactly once, when this Table
is deleted
with the Table::delete
method.
Table::on_delete
resolves when the subscription message is sent, not when
the delete event occurs.
sourcepub fn remove(&self, input: Py<PyAny>) -> PyResult<()>
pub fn remove(&self, input: Py<PyAny>) -> PyResult<()>
Removes rows from this Table
with the index
column values supplied.
§Arguments
indices
- A list ofindex
column values for rows that should be removed.
§JavaScript Examples
await table.remove([1, 2, 3]);
§Python Examples
tbl = Table({"a": [1, 2, 3]}, index="a")
tbl.remove([2, 3])
§Examples
table.remove(UpdateData::Csv("index\n1\n2\n3")).await?;
sourcepub fn remove_delete(&self, callback_id: u32) -> PyResult<()>
pub fn remove_delete(&self, callback_id: u32) -> PyResult<()>
Removes a listener with a given ID, as returned by a previous call to Table::on_delete
.
sourcepub fn schema(&self) -> PyResult<HashMap<String, String>>
pub fn schema(&self) -> PyResult<HashMap<String, String>>
Returns a table’s Schema
, a mapping of column names to column types.
The mapping of a Table
’s column names to data types is referred to as a
Schema
. Each column has a unique name and a data type, one of:
"boolean"
- A boolean type"date"
- A timesonze-agnostic date type (month/day/year)"datetime"
- A millisecond-precision datetime type in the UTC timezone"float"
- A 64 bit float"integer"
- A signed 32 bit integer (the integer type supported by JavaScript)"string"
- AString
data type (encoded internally as a dictionary)
Note that all Table
columns are nullable, regardless of the data type.
sourcepub fn validate_expressions(&self, expression: Py<PyAny>) -> PyResult<Py<PyAny>>
pub fn validate_expressions(&self, expression: Py<PyAny>) -> PyResult<Py<PyAny>>
Validates the given expressions.
§Python Examples
exprs = client.validate_expressions({"computed": '"Quantity" + 4'})
sourcepub fn view(&self, config: Option<Py<PyDict>>) -> PyResult<View>
pub fn view(&self, config: Option<Py<PyDict>>) -> PyResult<View>
Create a new View
from this table with a specified ViewConfigUpdate
.
See View
struct.
§JavaScript Examples
const view = await table.view({
columns: ["Sales"],
aggregates: { Sales: "sum" },
group_by: ["Region", "Country"],
filter: [["Category", "in", ["Furniture", "Technology"]]],
});
§Python Examples
view = table.view(
columns=["Sales"],
aggregates={"Sales": "sum"},
group_by=["Region", "Country"],
filter=[["Category", "in", ["Furniture", "Technology"]]]
)
§Examples
use crate::config::*;
let view = table
.view(Some(ViewConfigUpdate {
columns: Some(vec![Some("Sales".into())]),
aggregates: Some(HashMap::from_iter(vec![("Sales".into(), "sum".into())])),
group_by: Some(vec!["Region".into(), "Country".into()]),
filter: Some(vec![Filter::new("Category", "in", &[
"Furniture",
"Technology",
])]),
..ViewConfigUpdate::default()
}))
.await?;
sourcepub fn replace(&self, input: Py<PyAny>) -> PyResult<()>
pub fn replace(&self, input: Py<PyAny>) -> PyResult<()>
Updates the rows of this table and any derived View
instances.
Calling Table::update
will trigger the View::on_update
callbacks
register to derived View
, and the call itself will not resolve until all
derived View
’s are notified.
When updating a Table
with an index
, Table::update
supports partial
updates, by omitting columns from the update data.
§Arguments
input
- The input data for thisTable
. The schema of aTable
is immutable after creation, so this method cannot be called with a schema.options
- Options for this update step - seeUpdateOptions
.
§JavaScript Examples
await table.update("x,y\n1,2");
§Python Examples
table.update("x,y\n1,2")
§Examples
let data = UpdateData::Csv("x,y\n1,2".into());
let opts = UpdateOptions::default();
table.update(data, opts).await?;
sourcepub fn update(
&self,
py: Python<'_>,
input: Py<PyAny>,
port_id: Option<u32>,
) -> PyResult<()>
pub fn update( &self, py: Python<'_>, input: Py<PyAny>, port_id: Option<u32>, ) -> PyResult<()>
Updates the rows of this table and any derived View
instances.
Calling Table::update
will trigger the View::on_update
callbacks
register to derived View
, and the call itself will not resolve until all
derived View
’s are notified.
When updating a Table
with an index
, Table::update
supports partial
updates, by omitting columns from the update data.
§Arguments
input
- The input data for thisTable
. The schema of aTable
is immutable after creation, so this method cannot be called with a schema.options
- Options for this update step - seeUpdateOptions
.
§JavaScript Examples
await table.update("x,y\n1,2");
§Python Examples
table.update("x,y\n1,2")
§Examples
let data = UpdateData::Csv("x,y\n1,2".into());
let opts = UpdateOptions::default();
table.update(data, opts).await?;
Trait Implementations§
source§impl HasPyGilRef for Table
impl HasPyGilRef for Table
§type AsRefTarget = PyCell<Table>
type AsRefTarget = PyCell<Table>
source§impl PyClassImpl for Table
impl PyClassImpl for Table
source§const IS_BASETYPE: bool = true
const IS_BASETYPE: bool = true
source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
§type ThreadChecker = SendablePyClass<Table>
type ThreadChecker = SendablePyClass<Table>
§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
§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>
source§impl PyMethods<Table> for PyClassImplCollector<Table>
impl PyMethods<Table> for PyClassImplCollector<Table>
fn py_methods(self) -> &'static PyClassItems
source§impl PyTypeInfo for Table
impl PyTypeInfo for Table
source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
PyTypeInfo::type_object
will be replaced by PyTypeInfo::type_object_bound
in a future PyO3 versionsource§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
PyTypeInfo::is_type_of
will be replaced by PyTypeInfo::is_type_of_bound
in a future PyO3 versionobject
is an instance of this type or a subclass of this type.source§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.source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
PyTypeInfo::is_exact_type_of
will be replaced by PyTypeInfo::is_exact_type_of_bound
in a future PyO3 versionobject
is an instance of this type.impl DerefToPyAny for Table
Auto Trait Implementations§
impl Freeze for Table
impl !RefUnwindSafe for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl !UnwindSafe for Table
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more