polars_core/frame/column/
series.rs
1use std::ops::{Deref, DerefMut};
2
3use super::Series;
4
5#[derive(Debug, Clone)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct SeriesColumn {
12 inner: Series,
13
14 #[cfg(debug_assertions)]
15 #[cfg_attr(feature = "serde", serde(skip))]
16 materialized_at: Option<std::sync::Arc<std::backtrace::Backtrace>>,
17}
18
19impl SeriesColumn {
20 #[track_caller]
21 pub fn new(series: Series) -> Self {
22 Self {
23 inner: series,
24
25 #[cfg(debug_assertions)]
26 materialized_at: if std::env::var("POLARS_TRACK_SERIES_MATERIALIZATION").as_deref()
27 == Ok("1")
28 {
29 Some(std::sync::Arc::new(
30 std::backtrace::Backtrace::force_capture(),
31 ))
32 } else {
33 None
34 },
35 }
36 }
37
38 pub fn materialized_at(&self) -> Option<&std::backtrace::Backtrace> {
39 #[cfg(debug_assertions)]
40 {
41 self.materialized_at.as_ref().map(|v| v.as_ref())
42 }
43
44 #[cfg(not(debug_assertions))]
45 None
46 }
47
48 pub fn take(self) -> Series {
49 self.inner
50 }
51}
52
53impl From<Series> for SeriesColumn {
54 #[track_caller]
55 #[inline(always)]
56 fn from(value: Series) -> Self {
57 Self::new(value)
58 }
59}
60
61impl Deref for SeriesColumn {
62 type Target = Series;
63
64 fn deref(&self) -> &Self::Target {
65 &self.inner
66 }
67}
68
69impl DerefMut for SeriesColumn {
70 fn deref_mut(&mut self) -> &mut Self::Target {
71 &mut self.inner
72 }
73}