-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathcontext.rs
More file actions
95 lines (78 loc) · 2.15 KB
/
Copy pathcontext.rs
File metadata and controls
95 lines (78 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::ops::Deref;
use std::sync::Arc;
use itertools::Itertools;
use pyo3::pyclass;
use pyo3::pymethods;
use vortex::array::ArrayContext;
use vortex::session::registry::Id;
use vortex::session::registry::ReadContext;
/// An ArrayContext captures an ordered set of encodings.
///
/// In a serialized array, encodings are identified by a positional index into such an
/// :class:`~vortex.ArrayContext`.
#[pyclass(name = "ArrayContext", module = "vortex", frozen)]
pub(crate) struct PyArrayContext(ArrayContext);
impl From<ArrayContext> for PyArrayContext {
fn from(context: ArrayContext) -> Self {
Self(context)
}
}
impl Deref for PyArrayContext {
type Target = ArrayContext;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[pymethods]
impl PyArrayContext {
#[new]
fn new() -> Self {
Self(ArrayContext::empty())
}
fn __str__(&self) -> String {
self.0.to_ids().iter().join(", ")
}
fn __len__(&self) -> usize {
self.to_ids().len()
}
}
/// A ReadContext captures an ordered set of encodings.
///
/// In a serialized array, encodings are identified by a positional index into such an
/// :class:`~vortex.ReadContext`.
#[pyclass(name = "ReadContext", module = "vortex", frozen)]
pub(crate) struct PyReadContext(ReadContext);
impl From<ReadContext> for PyReadContext {
fn from(context: ReadContext) -> Self {
Self(context)
}
}
impl Deref for PyReadContext {
type Target = ReadContext;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[pymethods]
impl PyReadContext {
#[new]
#[expect(clippy::disallowed_methods, reason = "interning a dynamic id")]
fn new(ids: Vec<String>) -> Self {
Self(ReadContext::new(
ids.into_iter().map(|i| Id::new(&i)).collect::<Arc<_>>(),
))
}
fn __str__(&self) -> String {
self.0.ids().iter().join(", ")
}
fn __len__(&self) -> usize {
self.ids().len()
}
}
impl PyReadContext {
pub(crate) fn clone_inner(&self) -> ReadContext {
self.0.clone()
}
}