Skip to content

Commit

Permalink
Fixing liniting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidek56 committed Dec 10, 2024
1 parent 3c19650 commit c58b2e4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { type LazyDataFrame, _LazyDataFrame } from "./lazy/dataframe";
import { Expr } from "./lazy/expr";
import { Series, _Series } from "./series";
import type {
CsvWriterOptions,
FillNullStrategy,
JoinOptions,
WriteAvroOptions,
CsvWriterOptions,
WriteIPCOptions,
WriteParquetOptions,
} from "./types";
Expand Down
2 changes: 1 addition & 1 deletion polars/lazy/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import pli from "../internals/polars_internal";
import type { Series } from "../series";
import type { Deserialize, GroupByOps, Serialize } from "../shared_traits";
import type {
CsvWriterOptions,
LazyJoinOptions,
LazyOptions,
CsvWriterOptions,
SinkParquetOptions,
} from "../types";
import {
Expand Down
29 changes: 21 additions & 8 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::prelude::*;
use napi::bindgen_prelude::*;
use napi::{JsBigInt, JsBoolean, JsDate, JsNumber, JsObject, JsString, JsUnknown};
use polars::prelude::NullStrategy;
use polars_io::cloud::CloudOptions;
use polars::prelude::*;
use polars_core::series::ops::NullBehavior;
use polars_io::cloud::CloudOptions;
use polars_io::RowIndex;
use std::collections::HashMap;
use std::num::NonZero;
Expand Down Expand Up @@ -831,18 +831,31 @@ impl FromNapiValue for Wrap<CsvWriterOptions> {
let obj = Object::from_napi_value(env, napi_val)?;
let include_bom = obj.get::<_, bool>("includeBom")?.unwrap_or(false);
let include_header = obj.get::<_, bool>("includeHeader")?.unwrap_or(true);
let batch_size = NonZero::new(obj.get::<_, i64>("batchSize")?.unwrap_or(1024) as usize).unwrap();
let maintain_order= obj.get::<_, bool>("maintainOrder")?.unwrap_or(true);
let batch_size =
NonZero::new(obj.get::<_, i64>("batchSize")?.unwrap_or(1024) as usize).unwrap();
let maintain_order = obj.get::<_, bool>("maintainOrder")?.unwrap_or(true);
let date_format = obj.get::<_, String>("dateFormat")?;
let time_format = obj.get::<_, String>("timeFormat")?;
let datetime_format = obj.get::<_, String>("datetimeFormat")?;
let float_scientific = obj.get::<_, bool>("floatScientific")?;
let float_precision = obj.get::<_, i32>("floatPrecision")?.map(|x| x as usize);
let separator = obj.get::<_, String>("separator")?.unwrap_or(",".to_owned()).as_bytes()[0];
let quote_char = obj.get::<_, String>("quoteChar")?.unwrap_or("\"".to_owned()).as_bytes()[0];
let null_value = obj.get::<_, String>("nullValue")?.unwrap_or(SerializeOptions::default().null);
let line_terminator = obj.get::<_, String>("lineTerminator")?.unwrap_or("\n".to_owned());
let quote_style = obj.get::<_, Wrap<QuoteStyle>>("quoteStyle")?.map_or(QuoteStyle::default(), |wrap| wrap.0);
let separator = obj
.get::<_, String>("separator")?
.unwrap_or(",".to_owned())
.as_bytes()[0];
let quote_char = obj
.get::<_, String>("quoteChar")?
.unwrap_or("\"".to_owned())
.as_bytes()[0];
let null_value = obj
.get::<_, String>("nullValue")?
.unwrap_or(SerializeOptions::default().null);
let line_terminator = obj
.get::<_, String>("lineTerminator")?
.unwrap_or("\n".to_owned());
let quote_style = obj
.get::<_, Wrap<QuoteStyle>>("quoteStyle")?
.map_or(QuoteStyle::default(), |wrap| wrap.0);

let serialize_options = SerializeOptions {
date_format,
Expand Down
2 changes: 1 addition & 1 deletion src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::prelude::*;
use crate::series::JsSeries;
use napi::JsUnknown;
use polars::frame::row::{infer_schema, Row};
use polars_io::csv::write::CsvWriterOptions;
use polars_io::mmap::MmapBytesReader;
use polars_io::RowIndex;
use polars_io::csv::write::CsvWriterOptions;
use std::borrow::Borrow;
use std::collections::HashMap;
use std::fs::File;
Expand Down
8 changes: 6 additions & 2 deletions src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,19 @@ impl JsLazyFrame {
}

#[napi(catch_unwind)]
pub fn sink_csv(&self, path: String,
pub fn sink_csv(
&self,
path: String,
options: Wrap<CsvWriterOptions>,
cloud_options: Option<HashMap<String, String>>,
max_retries: Option<u32>,
) -> napi::Result<()> {
let cloud_options = parse_cloud_options(&path, cloud_options, max_retries);
let path_buf: PathBuf = PathBuf::from(path);
let ldf = self.ldf.clone().with_comm_subplan_elim(false);
let _ = ldf.sink_csv(path_buf, options.0, cloud_options).map_err(JsPolarsErr::from);
let _ = ldf
.sink_csv(path_buf, options.0, cloud_options)
.map_err(JsPolarsErr::from);
Ok(())
}

Expand Down

0 comments on commit c58b2e4

Please sign in to comment.