@@ -64,6 +64,20 @@ let schema = Schema::new(&fields);
64
64
let batch = RecordBatch :: try_new (schema . into (), arrays )? ;
65
65
```
66
66
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
+
67
81
### Serialize to ` arrow2 ` arrays
68
82
``` rust
69
83
use serde_arrow :: schema :: {TracingOptions , SerdeArrowSchema };
@@ -87,27 +101,7 @@ let fields =
87
101
let arrays = serde_arrow :: to_arrow2 (& fields , & records )? ;
88
102
```
89
103
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
111
105
[ arrow2 guide] [ arrow2-guide ] . For parquet:
112
106
113
107
``` rust,ignore
@@ -121,12 +115,14 @@ write_chunk(
121
115
)?;
122
116
```
123
117
118
+ ### Usage from python
119
+
124
120
The written file can now be read in Python via
125
121
126
- ### Polars
127
122
``` 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" )
130
126
shape: (3 , 2 )
131
127
┌─────┬─────┐
132
128
│ a ┆ b │
@@ -137,12 +133,10 @@ shape: (3, 2)
137
133
│ 2.0 ┆ 2 │
138
134
│ 3.0 ┆ 3 │
139
135
└─────┴─────┘
140
- ```
141
136
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" )
146
140
a b
147
141
0 1.0 1
148
142
1 2.0 2
0 commit comments