Skip to content

Commit 0833eb0

Browse files
committed
Improve heading to content ratio, reorganize content
1 parent b966b4c commit 0833eb0

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

Readme.md

+23-29
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ let schema = Schema::new(&fields);
6464
let batch = RecordBatch::try_new(schema.into(), arrays)?;
6565
```
6666

67+
This `RecordBatch` can now be written to disk using [ArrowWriter] from the [parquet] crate.
68+
69+
[ArrowWriter]: https://docs.rs/parquet/latest/parquet/arrow/arrow_writer/struct.ArrowWriter.html
70+
[parquet]: https://docs.rs/parquet/latest/parquet/
71+
72+
73+
```rust
74+
let file = File::create("example.pq");
75+
let mut writer = ArrowWriter::try_new(file, batch.schema(), None)?;
76+
writer.write(&batch)?;
77+
writer.close()?;
78+
```
79+
80+
6781
### Serialize to `arrow2` arrays
6882
```rust
6983
use serde_arrow::schema::{TracingOptions, SerdeArrowSchema};
@@ -87,27 +101,7 @@ let fields =
87101
let arrays = serde_arrow::to_arrow2(&fields, &records)?;
88102
```
89103

90-
These arrays can now be written to disk in formats such as Parquet using the
91-
appropriate Arrow or Arrow2 APIs.
92-
93-
### Write `arrow` `RecordBatch` to Parquet
94-
95-
You can write the `RecordBatch` to a Parquet file using [ArrowWriter] from the
96-
[parquet] crate:
97-
98-
[ArrowWriter]: https://docs.rs/parquet/latest/parquet/arrow/arrow_writer/struct.ArrowWriter.html
99-
[parquet]: https://docs.rs/parquet/latest/parquet/
100-
101-
102-
```rust
103-
let file = File::create("example.pq");
104-
let mut writer = ArrowWriter::try_new(file, batch.schema(), None)?;
105-
writer.write(&batch)?;
106-
writer.close()?;
107-
```
108-
109-
### Write `arrow2` arrays to Parquet
110-
using the helper method defined in the
104+
These arrays can now be written to disk using the helper method defined in the
111105
[arrow2 guide][arrow2-guide]. For parquet:
112106

113107
```rust,ignore
@@ -121,12 +115,14 @@ write_chunk(
121115
)?;
122116
```
123117

118+
### Usage from python
119+
124120
The written file can now be read in Python via
125121

126-
### Polars
127122
```python
128-
import polars as pl
129-
pl.read_parquet("example.pq")
123+
# using polars
124+
>>> import polars as pl
125+
>>> pl.read_parquet("example.pq")
130126
shape: (3, 2)
131127
┌─────┬─────┐
132128
│ a ┆ b │
@@ -137,12 +133,10 @@ shape: (3, 2)
137133
2.02
138134
3.03
139135
└─────┴─────┘
140-
```
141136

142-
### Pandas
143-
```python
144-
import pandas as pd
145-
pd.read_parquet("example.pq")
137+
# using pandas
138+
>>> import pandas as pd
139+
>>> pd.read_parquet("example.pq")
146140
a b
147141
0 1.0 1
148142
1 2.0 2

0 commit comments

Comments
 (0)