Skip to content

Commit

Permalink
Updated Polars to 0.38.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 19, 2024
1 parent 360ee08 commit 39a877e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.9.1 (unreleased)

- Updated Polars to 0.38.2
- Updated Polars to 0.38.3
- Added support for writing JSON to string
- Added support for writing Parquet to `StringIO`
- Added `data_page_size` option to `write_parquet` method
Expand Down
66 changes: 33 additions & 33 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions ext/polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ ahash = "0.8"
chrono = "0.4"
either = "1.8"
magnus = "0.6"
polars-core = "=0.38.2"
polars-parquet = "=0.38.2"
polars-utils = "=0.38.2"
polars-core = "=0.38.3"
polars-parquet = "=0.38.3"
polars-utils = "=0.38.3"
serde_json = "1"
smartstring = "1"

[dependencies.polars]
version = "=0.38.2"
version = "=0.38.3"
features = [
"abs",
"approx_unique",
Expand Down
15 changes: 15 additions & 0 deletions ext/polars/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,21 @@ impl TryConvert for Wrap<ListToStructWidthStrategy> {
}
}

impl TryConvert for Wrap<NonExistent> {
fn try_convert(ob: Value) -> RbResult<Self> {
let parsed = match String::try_convert(ob)?.as_str() {
"null" => NonExistent::Null,
"raise" => NonExistent::Raise,
v => {
return Err(RbValueError::new_err(format!(
"`non_existent` must be one of {{'null', 'raise'}}, got {v}",
)))
}
};
Ok(Wrap(parsed))
}
}

impl TryConvert for Wrap<NullBehavior> {
fn try_convert(ob: Value) -> RbResult<Self> {
let parsed = match String::try_convert(ob)?.as_str() {
Expand Down
9 changes: 7 additions & 2 deletions ext/polars/src/expr/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ impl RbExpr {
self.inner.clone().dt().cast_time_unit(tu.0).into()
}

pub fn dt_replace_time_zone(&self, time_zone: Option<String>, ambiguous: &Self) -> Self {
pub fn dt_replace_time_zone(
&self,
time_zone: Option<String>,
ambiguous: &Self,
non_existent: Wrap<NonExistent>,
) -> Self {
self.inner
.clone()
.dt()
.replace_time_zone(time_zone, ambiguous.inner.clone())
.replace_time_zone(time_zone, ambiguous.inner.clone(), non_existent.0)
.into()
}

Expand Down
2 changes: 1 addition & 1 deletion ext/polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
class.define_method("dt_cast_time_unit", method!(RbExpr::dt_cast_time_unit, 1))?;
class.define_method(
"dt_replace_time_zone",
method!(RbExpr::dt_replace_time_zone, 2),
method!(RbExpr::dt_replace_time_zone, 3),
)?;
class.define_method("dt_truncate", method!(RbExpr::dt_truncate, 2))?;
class.define_method("dt_month_start", method!(RbExpr::dt_month_start, 0))?;
Expand Down
2 changes: 1 addition & 1 deletion lib/polars/data_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ def write_parquet(
# df.estimated_size
# # => 25888898
# df.estimated_size("mb")
# # => 26.702880859375
# # => 17.0601749420166
def estimated_size(unit = "b")
sz = _df.estimated_size
Utils.scale_bytes(sz, to: unit)
Expand Down
14 changes: 10 additions & 4 deletions lib/polars/date_time_expr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1027,14 +1027,20 @@ def convert_time_zone(tz)
# Different from `convert_time_zone`, this will also modify
# the underlying timestamp,
#
# @param tz [String]
# Time zone for the `Datetime` Series.
# @param time_zone [String]
# Time zone for the `Datetime` Series. Pass `nil` to unset time zone.
# @param use_earliest [Boolean]
# Determine how to deal with ambiguous datetimes.
# @param ambiguous [String]
# Determine how to deal with ambiguous datetimes.
# @param non_existent [String]
# Determine how to deal with non-existent datetimes.
#
# @return [Expr]
def replace_time_zone(tz, use_earliest: nil, ambiguous: "raise")
def replace_time_zone(time_zone, use_earliest: nil, ambiguous: "raise", non_existent: "raise")
ambiguous = Utils.rename_use_earliest_to_ambiguous(use_earliest, ambiguous)
ambiguous = Polars.lit(ambiguous) unless ambiguous.is_a?(Expr)
Utils.wrap_expr(_rbexpr.dt_replace_time_zone(tz, ambiguous._rbexpr))
Utils.wrap_expr(_rbexpr.dt_replace_time_zone(time_zone, ambiguous._rbexpr, non_existent))
end

# Extract the days from a Duration type.
Expand Down
12 changes: 9 additions & 3 deletions lib/polars/date_time_name_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,14 @@ def convert_time_zone(tz)
# Different from `with_time_zone`, this will also modify
# the underlying timestamp.
#
# @param tz [String]
# Time zone for the `Datetime` Series.
# @param time_zone [String]
# Time zone for the `Datetime` Series. Pass `nil` to unset time zone.
# @param use_earliest [Boolean]
# Determine how to deal with ambiguous datetimes.
# @param ambiguous [String]
# Determine how to deal with ambiguous datetimes.
# @param non_existent [String]
# Determine how to deal with non-existent datetimes.
#
# @return [Series]
#
Expand Down Expand Up @@ -982,7 +988,7 @@ def convert_time_zone(tz)
# # 1585717200
# # 1588309200
# # ]
def replace_time_zone(tz)
def replace_time_zone(time_zone, use_earliest: nil, ambiguous: "raise", non_existent: "raise")
super
end

Expand Down
Loading

0 comments on commit 39a877e

Please sign in to comment.