Skip to content

Commit e006f3d

Browse files
committed
Moved warnings to Ruby
1 parent 3d2fbd2 commit e006f3d

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/polars/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ magnus = { version = "0.8", features = ["chrono"] }
2020
num-traits = "0.2"
2121
polars-core = "=0.51.0"
2222
polars-dtype = "=0.51.0"
23+
polars-error = "=0.51.0"
2324
polars-io = "=0.51.0"
2425
polars-lazy = { version = "=0.51.0", features = ["catalog"] }
2526
polars-plan = "=0.51.0"

ext/polars/src/on_startup.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@ use std::any::Any;
22
use std::sync::Arc;
33
use std::sync::OnceLock;
44

5-
use magnus::{IntoValue, Ruby};
5+
use magnus::{IntoValue, Ruby, Value, prelude::*};
66
use polars::prelude::*;
77
use polars_core::chunked_array::object::builder::ObjectChunkedBuilder;
88
use polars_core::chunked_array::object::registry;
99
use polars_core::chunked_array::object::registry::AnonymousObjectBuilder;
1010
use polars_core::prelude::AnyValue;
11+
use polars_error::PolarsWarning;
1112

1213
use crate::Wrap;
1314
use crate::prelude::ObjectValue;
15+
use crate::rb_modules::utils;
16+
17+
fn warning_function(msg: &str, _warning: PolarsWarning) {
18+
if let Err(e) = utils().funcall::<_, _, Value>("_polars_warn", (msg.to_string(),)) {
19+
eprintln!("{e}")
20+
}
21+
}
1422

1523
static POLARS_REGISTRY_INIT_LOCK: OnceLock<()> = OnceLock::new();
1624

@@ -40,8 +48,7 @@ pub(crate) fn register_startup_deps() {
4048
rbobject_converter,
4149
physical_dtype,
4250
);
43-
// TODO
4451
// Register warning function for `polars_warn!`.
45-
// polars_error::set_warning_function(warning_function);
52+
polars_error::set_warning_function(warning_function);
4653
});
4754
}

lib/polars/utils/various.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def self.scale_bytes(sz, to:)
7575
end
7676
end
7777

78+
def self._polars_warn(msg)
79+
warn msg
80+
end
81+
7882
def self.extend_bool(value, n_match, value_name, match_name)
7983
values = bool?(value) ? [value] * n_match : value
8084
if n_match != values.length

0 commit comments

Comments
 (0)