Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-python/src/series/mod.rs
7889 views
1
#[cfg(feature = "pymethods")]
2
mod aggregation;
3
#[cfg(feature = "pymethods")]
4
mod arithmetic;
5
#[cfg(feature = "pymethods")]
6
mod buffers;
7
#[cfg(feature = "pymethods")]
8
mod c_interface;
9
#[cfg(feature = "pymethods")]
10
mod comparison;
11
#[cfg(feature = "pymethods")]
12
pub(crate) mod construction;
13
#[cfg(feature = "pymethods")]
14
mod export;
15
#[cfg(feature = "pymethods")]
16
mod general;
17
#[cfg(feature = "pymethods")]
18
mod import;
19
#[cfg(feature = "pymethods")]
20
mod map;
21
#[cfg(feature = "pymethods")]
22
mod numpy_ufunc;
23
#[cfg(feature = "pymethods")]
24
mod scatter;
25
pub(crate) use import::import_schema_pycapsule;
26
use parking_lot::RwLock;
27
use polars::prelude::{Column, Series};
28
use pyo3::pyclass;
29
30
#[pyclass(frozen)]
31
#[repr(transparent)]
32
pub struct PySeries {
33
pub series: RwLock<Series>,
34
}
35
36
impl Clone for PySeries {
37
fn clone(&self) -> Self {
38
Self {
39
series: RwLock::new(self.series.read().clone()),
40
}
41
}
42
}
43
44
impl From<Series> for PySeries {
45
fn from(series: Series) -> Self {
46
Self::new(series)
47
}
48
}
49
50
impl PySeries {
51
pub(crate) fn new(series: Series) -> Self {
52
PySeries {
53
series: RwLock::new(series),
54
}
55
}
56
}
57
58
pub(crate) trait ToSeries {
59
fn to_series(self) -> Vec<Series>;
60
}
61
62
impl ToSeries for Vec<PySeries> {
63
fn to_series(self) -> Vec<Series> {
64
self.into_iter().map(|s| s.series.into_inner()).collect()
65
}
66
}
67
68
pub(crate) trait ToPySeries {
69
fn to_pyseries(self) -> Vec<PySeries>;
70
}
71
72
impl ToPySeries for Vec<Series> {
73
fn to_pyseries(self) -> Vec<PySeries> {
74
self.into_iter().map(PySeries::from).collect()
75
}
76
}
77
78
impl ToPySeries for Vec<Column> {
79
fn to_pyseries(self) -> Vec<PySeries> {
80
// @scalar-opt
81
let series: Vec<Series> = self
82
.into_iter()
83
.map(|c| c.take_materialized_series())
84
.collect();
85
series.to_pyseries()
86
}
87
}
88
89