Skip to content

Commit

Permalink
refactor(rust): Refactor Schema to use generic struct from new `pol…
Browse files Browse the repository at this point in the history
…ars-schema` crate (#18539)
  • Loading branch information
nameexhaustion authored Sep 4, 2024
1 parent 42cf395 commit 5774962
Show file tree
Hide file tree
Showing 32 changed files with 518 additions and 454 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ flate2 = { version = "1", default-features = false }
futures = "0.3.25"
hashbrown = { version = "0.14", features = ["rayon", "ahash", "serde"] }
hex = "0.4.3"
indexmap = { version = "2", features = ["std"] }
indexmap = { version = "2", features = ["std", "serde"] }
itoa = "1.0.6"
itoap = { version = "1", features = ["simd"] }
libc = "0.2"
Expand Down Expand Up @@ -112,6 +112,7 @@ polars-pipe = { version = "0.42.0", path = "crates/polars-pipe", default-feature
polars-plan = { version = "0.42.0", path = "crates/polars-plan", default-features = false }
polars-python = { version = "0.42.0", path = "crates/polars-python", default-features = false }
polars-row = { version = "0.42.0", path = "crates/polars-row", default-features = false }
polars-schema = { version = "0.42.0", path = "crates/polars-schema", default-features = false }
polars-sql = { version = "0.42.0", path = "crates/polars-sql", default-features = false }
polars-stream = { version = "0.42.0", path = "crates/polars-stream", default-features = false }
polars-time = { version = "0.42.0", path = "crates/polars-time", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion crates/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Core of the Polars DataFrame library"
polars-compute = { workspace = true }
polars-error = { workspace = true }
polars-row = { workspace = true }
polars-schema = { workspace = true }
polars-utils = { workspace = true }

ahash = { workspace = true }
Expand Down Expand Up @@ -116,7 +117,7 @@ dtype-struct = []
bigidx = ["arrow/bigidx", "polars-utils/bigidx"]
python = []

serde = ["dep:serde", "bitflags/serde"]
serde = ["dep:serde", "bitflags/serde", "polars-schema/serde"]
serde-lazy = ["serde", "arrow/serde", "indexmap/serde", "chrono/serde"]

docs-selection = [
Expand Down
6 changes: 6 additions & 0 deletions crates/polars-core/src/datatypes/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub struct Field {
pub dtype: DataType,
}

impl From<Field> for (PlSmallStr, DataType) {
fn from(value: Field) -> Self {
(value.name, value.dtype)
}
}

pub type FieldRef = Arc<Field>;

impl Field {
Expand Down
5 changes: 4 additions & 1 deletion crates/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ impl DataFrame {
/// # Ok::<(), PolarsError>(())
/// ```
pub fn schema(&self) -> Schema {
self.columns.as_slice().into()
self.columns
.iter()
.map(|x| (x.name().clone(), x.dtype().clone()))
.collect()
}

/// Get a reference to the [`DataFrame`] columns.
Expand Down
Loading

0 comments on commit 5774962

Please sign in to comment.