Skip to content

Commit

Permalink
Added support for writing Parquet to StringIO - #51
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 18, 2024
1 parent c154ebe commit 91f06be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Updated Polars to 0.38.2
- Added support for writing JSON to string
- Added support for writing Parquet to StringIO

## 0.9.0 (2024-03-03)

Expand Down
8 changes: 7 additions & 1 deletion ext/polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,13 @@ impl RbDataFrame {
.finish(&mut self.df.borrow_mut())
.map_err(RbPolarsErr::from)?;
} else {
todo!();
let buf = get_file_like(rb_f, true)?;
ParquetWriter::new(buf)
.with_compression(compression)
.with_statistics(statistics)
.with_row_group_size(row_group_size)
.finish(&mut self.df.borrow_mut())
.map_err(RbPolarsErr::from)?;
}

Ok(())
Expand Down
10 changes: 10 additions & 0 deletions test/parquet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def test_write_parquet
assert_nil df.write_parquet(temp_path)
end

def test_write_parquet_io
require "stringio"

df = Polars::DataFrame.new({"a" => [1, 2, 3], "b" => ["one", "two", "three"]})
io = StringIO.new
df.write_parquet(io)
io.rewind
assert_frame df, Polars.read_parquet(io)
end

def test_write_parquet_struct
df = Polars::DataFrame.new({"a" => [{"f1" => 1}, {"f1" => 2}]})
assert_nil df.write_parquet(temp_path)
Expand Down

0 comments on commit 91f06be

Please sign in to comment.