Skip to content

Commit

Permalink
ci[python]: allow deprecated calls (#4958)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 24, 2022
1 parent 7d33cd0 commit b2265a7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
3 changes: 2 additions & 1 deletion polars-sql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "polars-sql"
name = "polarssql"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.2.22", features = ["derive"] }
serde = "1"
serde_json = { version = "1" }
sqlparser = { version = "0.15.0" }
Expand Down
9 changes: 6 additions & 3 deletions polars-sql/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ impl SQLContext {
}
}

pub fn register(&mut self, name: &str, df: &DataFrame) {
self.table_map.insert(name.to_owned(), df.clone().lazy());
pub fn register(&mut self, name: &str, lf: LazyFrame) {
self.table_map.insert(name.to_owned(), lf);
}

fn execute_select(&self, select_stmt: &Select) -> PolarsResult<LazyFrame> {
// Determine involved dataframe
// Implicit join require some more work in query parsers, Explicit join are preferred for now.
let tbl = select_stmt.from.get(0).unwrap();
let tbl = select_stmt
.from
.get(0)
.ok_or_else(|| PolarsError::ComputeError("No table name provided in query".into()))?;
let mut alias_map = PlHashMap::new();
let tbl_name = match &tbl.relation {
TableFactor::Table { name, alias, .. } => {
Expand Down
8 changes: 4 additions & 4 deletions polars-sql/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub use context::SQLContext;

mod context;
mod sql_expr;

pub use context::SQLContext;

#[cfg(test)]
mod test {
use polars::prelude::*;
Expand All @@ -19,7 +19,7 @@ mod test {
fn test_simple_select() -> PolarsResult<()> {
let df = create_sample_df()?;
let mut context = SQLContext::new();
context.register("df", &df);
context.register("df", df.clone().lazy());
let df_sql = context
.execute(
r#"
Expand All @@ -44,7 +44,7 @@ mod test {
fn test_groupby_simple() -> PolarsResult<()> {
let df = create_sample_df()?;
let mut context = SQLContext::new();
context.register("df", &df);
context.register("df", df.clone().lazy());
let df_sql = context
.execute(
r#"
Expand Down
32 changes: 32 additions & 0 deletions polars-sql/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::process::exit;

use clap::Parser;
use polars::prelude::*;
use polarssql::SQLContext;

#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(value_parser)]
sql: String,
}

fn run() -> PolarsResult<DataFrame> {
let cli = Cli::parse();

let mut context = SQLContext::new();

println!("{:?}", cli.sql);

let q = context.execute(&cli.sql)?;
let out = q.limit(100).collect()?;

Ok(out)
}

fn main() -> PolarsResult<()> {
let out = run()?;
println!("{}", out);

Ok(())
}
2 changes: 2 additions & 0 deletions py-polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ impl PyDataFrame {
Ok(df.into())
}

#[allow(deprecated)]
pub fn groupby_quantile(
&self,
by: Vec<&str>,
Expand Down Expand Up @@ -1329,6 +1330,7 @@ impl PyDataFrame {
}
}

#[allow(deprecated)]
fn finish_groupby(gb: GroupBy, agg: &str) -> PyResult<PyDataFrame> {
Python::with_gil(|py| {
let df = py.allow_threads(|| match agg {
Expand Down

0 comments on commit b2265a7

Please sign in to comment.