Skip to content

Commit 69d2e33

Browse files
committed
Integrations: Harmonize pages about data frames (pandas, Dask, Polars)
1 parent 0f7bb5c commit 69d2e33

File tree

5 files changed

+234
-54
lines changed

5 files changed

+234
-54
lines changed

docs/integrate/dask/index.md

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
(dask)=
22
# Dask
33

4+
:::{div} .float-right .text-right
5+
[![Dask logo](https://github.com/crate/crate-clients-tools/assets/453543/99bd2234-c501-479b-ade7-bcc2bfc1f288){height=60px loading=lazy}][Dask]
6+
<br>
7+
[![Dask CI](https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-dask.yml?branch=main)](https://github.com/crate/cratedb-examples/actions/workflows/dataframe-dask.yml)
8+
:::
9+
:::{div} .clearfix
10+
:::
11+
412
:::{rubric} About
513
:::
14+
615
[Dask] is a parallel computing library for analytics with task scheduling.
716
It is built on top of the Python programming language, making it easy to scale
817
the Python libraries that you know and love, like NumPy, pandas, and scikit-learn.
918

10-
```{div}
11-
:style: "float: right"
12-
[![](https://github.com/crate/crate-clients-tools/assets/453543/99bd2234-c501-479b-ade7-bcc2bfc1f288){w=180px}](https://www.dask.org/)
13-
```
14-
1519
- [Dask DataFrames] help you process large tabular data by parallelizing pandas,
1620
either on your laptop for larger-than-memory computing, or on a distributed
1721
cluster of computers.
@@ -20,16 +24,78 @@ the Python libraries that you know and love, like NumPy, pandas, and scikit-lear
2024
generic Python workflows across a Dask cluster with minimal code changes,
2125
by extending Python's `concurrent.futures` interface.
2226

23-
```{div}
24-
:style: "clear: both"
27+
:::{rubric} Install
28+
:::
29+
30+
```shell
31+
pip install 'dask[dataframe]' 'sqlalchemy-cratedb'
2532
```
2633

27-
:::{rubric} Learn
34+
:::{rubric} Synopsis
2835
:::
36+
37+
Write Dask dataframe to CrateDB.
38+
39+
`example.py`
40+
```python
41+
import dask.dataframe as dd
42+
from sqlalchemy_cratedb import insert_bulk
43+
44+
CRATEDB_URI = "crate://crate:crate@localhost:4200"
45+
TABLE_NAME = "example"
46+
47+
df = makeTimeDataFrame(rows=500_000, freq="s")
48+
ddf = dd.from_pandas(df, npartitions=4)
49+
ddf.to_sql(
50+
TABLE_NAME,
51+
uri=CRATEDB_URI,
52+
index=False,
53+
if_exists="replace",
54+
chunksize=20_000,
55+
parallel=True,
56+
method=insert_bulk,
57+
)
58+
```
59+
60+
:::{rubric} Quickstart example
61+
:::
62+
63+
Create the file `example.py` including the synopsis code shared above.
64+
Complete the example by using the `makeTimeDataFrame()` function.
65+
66+
:::{literalinclude} ../pandas/makeTimeDataFrame.py
67+
:::
68+
69+
:::{include} /connect/_cratedb.md
70+
:::
71+
```shell
72+
pip install 'dask[dataframe]' 'sqlalchemy-cratedb'
73+
python example.py
74+
```
75+
76+
:::{rubric} Full example
77+
:::
78+
79+
:::{card}
80+
:link: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/dask
81+
:link-type: url
82+
{material-regular}`play_arrow;2em`
83+
Connect to CrateDB and CrateDB Cloud using Dask.
84+
+++
85+
Includes basic examples of how to use Dask with CrateDB.
86+
:::
87+
88+
:::{rubric} Guides
89+
:::
90+
2991
- {ref}`dask-usage`
30-
- [Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]
92+
93+
:::{rubric} Related sections
94+
:::
95+
96+
- {ref}`Efficient batch/bulk INSERT operations for pandas, Dask, and Polars <sqlalchemy-cratedb:dataframe>`
97+
- {ref}`arrow-import-parquet`
3198
- [Import weather data using Dask]
32-
- [Dask code examples]
3399

34100

35101
:::{toctree}
@@ -40,8 +106,6 @@ Usage <usage>
40106

41107

42108
[Dask]: https://www.dask.org/
43-
[Dask code examples]: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/dask
44109
[Dask DataFrames]: https://docs.dask.org/en/latest/dataframe.html
45110
[Dask Futures]: https://docs.dask.org/en/latest/futures.html
46-
[Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]: https://cratedb.com/docs/python/en/latest/by-example/sqlalchemy/dataframe.html
47111
[Import weather data using Dask]: https://github.com/crate/cratedb-examples/blob/main/topic/timeseries/dask-weather-data-import.ipynb

docs/integrate/pandas/efficient-ingest.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
(pandas-bulk-import)=
2+
(pandas-efficient-import)=
3+
24
# Efficient bulk imports with pandas
35

46
## Introduction

docs/integrate/pandas/index.md

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
(pandas)=
22
# pandas
33

4-
```{div}
5-
:style: "float: right"
6-
[![](https://pandas.pydata.org/static/img/pandas.svg){w=180px}](https://pandas.pydata.org/)
7-
```
8-
```{div} .clearfix
9-
```
4+
:::{div} .float-right .text-right
5+
[![pandas logo](https://pandas.pydata.org/static/img/pandas.svg){height=60px loading=lazy}][pandas]
6+
<br>
7+
[![pandas CI](https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-pandas.yml?branch=main)](https://github.com/crate/cratedb-examples/actions/workflows/dataframe-pandas.yml)
8+
:::
9+
:::{div} .clearfix
10+
:::
1011

1112
:::{rubric} About
1213
:::
@@ -15,35 +16,83 @@
1516
and manipulation tool, built on top of the Python programming language. It offers
1617
data structures and operations for manipulating numerical tables and time series.
1718

18-
:::{rubric} Data Model
19+
Pandas is built around data structures called Series and DataFrames. Data for these
20+
collections can be imported from various file formats such as comma-separated values,
21+
JSON, Parquet, SQL database tables or queries, and Microsoft Excel.
22+
A Series is a 1-dimensional data structure built on top of NumPy's array.
23+
24+
:::{rubric} Install
1925
:::
20-
- Pandas is built around data structures called Series and DataFrames. Data for these
21-
collections can be imported from various file formats such as comma-separated values,
22-
JSON, Parquet, SQL database tables or queries, and Microsoft Excel.
23-
- A Series is a 1-dimensional data structure built on top of NumPy's array.
24-
- Pandas includes support for time series, such as the ability to interpolate values
25-
and filter using a range of timestamps.
26-
- By default, a Pandas index is a series of integers ascending from 0, similar to the
27-
indices of Python arrays. However, indices can use any NumPy data type, including
28-
floating point, timestamps, or strings.
29-
- Pandas supports hierarchical indices with multiple values per data point. An index
30-
with this structure, called a "MultiIndex", allows a single DataFrame to represent
31-
multiple dimensions, similar to a pivot table in Microsoft Excel. Each level of a
32-
MultiIndex can be given a unique name.
3326

27+
```shell
28+
pip install pandas sqlalchemy-cratedb
29+
```
3430

35-
:::{rubric} Learn
31+
:::{rubric} Synopsis
3632
:::
33+
34+
Write pandas dataframe to CrateDB.
35+
36+
`example.py`
37+
```python
38+
import sqlalchemy as sa
39+
from sqlalchemy_cratedb import insert_bulk
40+
41+
CRATEDB_URI = "crate://crate:crate@localhost:4200"
42+
TABLE_NAME = "example"
43+
44+
df = makeTimeDataFrame(rows=500_000, freq="s")
45+
engine = sa.create_engine(CRATEDB_URI)
46+
df.to_sql(
47+
name=TABLE_NAME,
48+
con=engine,
49+
if_exists="replace",
50+
index=False,
51+
chunksize=20_000,
52+
method=insert_bulk,
53+
)
54+
```
55+
56+
:::{rubric} Quickstart example
57+
:::
58+
59+
Create the file `example.py` including the synopsis code shared above.
60+
Complete the example by using the `makeTimeDataFrame()` function.
61+
62+
:::{literalinclude} ../pandas/makeTimeDataFrame.py
63+
:::
64+
65+
:::{include} /connect/_cratedb.md
66+
:::
67+
```shell
68+
pip install pandas sqlalchemy-cratedb
69+
python example.py
70+
```
71+
72+
:::{rubric} Full example
73+
:::
74+
75+
:::{card}
76+
:link: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/pandas
77+
:link-type: url
78+
{material-regular}`play_arrow;2em`
79+
Connect to CrateDB and CrateDB Cloud using pandas.
80+
+++
81+
Includes basic examples of how to use pandas with CrateDB.
82+
:::
83+
84+
:::{rubric} Guides
85+
:::
86+
87+
- {ref}`pandas-efficient-import`
3788
- {ref}`pandas-tutorial-start`
3889
- {ref}`pandas-tutorial-jupyter`
39-
- {ref}`arrow-import-parquet`
40-
- {ref}`pandas-bulk-import`
41-
- See also: {ref}`dask-bulk-import`
42-
- See also: [Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]
4390

44-
:::{rubric} Code examples
91+
:::{rubric} Related sections
4592
:::
46-
- [pandas code examples]
93+
94+
- {ref}`Efficient batch/bulk INSERT operations for pandas, Dask, and Polars <sqlalchemy-cratedb:dataframe>`
95+
- {ref}`arrow-import-parquet`
4796

4897

4998
:::{toctree}
@@ -55,6 +104,4 @@ Efficient ingest <efficient-ingest>
55104
:::
56105

57106

58-
[Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]: https://cratedb.com/docs/python/en/latest/by-example/sqlalchemy/dataframe.html
59107
[pandas]: https://pandas.pydata.org/
60-
[pandas code examples]: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/pandas

docs/integrate/polars/index.md

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
(polars)=
22
# Polars
33

4-
```{div}
5-
:style: "float: right; margin-left: 0.5em"
6-
[![Polars logo](https://github.com/pola-rs/polars-static/raw/master/logos/polars-logo-dark.svg){w=180px}][Polars]
7-
```
8-
```{div} .clearfix
9-
```
4+
:::{div} .float-right .text-right
5+
[![Polars logo](https://github.com/pola-rs/polars-static/raw/master/logos/polars-logo-dark.svg){height=60px loading=lazy}][Polars]
6+
<br>
7+
[![Polars CI](https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-polars.yml?branch=main)](https://github.com/crate/cratedb-examples/actions/workflows/dataframe-polars.yml)
8+
:::
9+
:::{div} .clearfix
10+
:::
1011

1112
:::{rubric} About
1213
:::
@@ -15,6 +16,13 @@
1516
Rust, Python, Node.js, and R, plus a SQL context. It is powered by a
1617
multithreaded, vectorized query engine and written in Rust.
1718

19+
:::{dropdown} Features and data formats
20+
21+
Polars is an open-source library for data manipulation, known for being
22+
one of the fastest data processing solutions on a single machine.
23+
It features a well-structured, typed API that is both expressive and
24+
easy to use.
25+
1826
- **Fast:** Written from scratch in Rust and with performance in mind,
1927
designed close to the machine, and without external dependencies.
2028

@@ -29,7 +37,7 @@ multithreaded, vectorized query engine and written in Rust.
2937
- **Out of Core:** The streaming API allows you to process your results without
3038
requiring all your data to be in memory at the same time.
3139

32-
- **Parallel:** Polars' multi-threaded query engine utilizes the power of your
40+
- **Parallel:** Polars' multithreaded query engine utilizes the power of your
3341
machine by dividing the workload among the available CPU cores without any
3442
additional configuration.
3543

@@ -41,9 +49,6 @@ multithreaded, vectorized query engine and written in Rust.
4149
community of developers. Everyone is encouraged to add new features and contribute.
4250
It is free to use under the MIT license.
4351

44-
:::{rubric} Data formats
45-
:::
46-
4752
Polars supports reading and writing to many common data formats.
4853
This allows you to easily integrate Polars into your existing data stack.
4954

@@ -53,11 +58,71 @@ This allows you to easily integrate Polars into your existing data stack.
5358
- Databases: MySQL, PostgreSQL, SQLite, Redshift, SQL Server, etc. (via ConnectorX)
5459
- Cloud storage: Amazon S3, Azure Blob/ADLS (via fsspec‑compatible backends)
5560

56-
:::{rubric} Learn
5761
:::
58-
- [Polars code examples]
62+
63+
:::{rubric} Install
64+
:::
65+
66+
```shell
67+
pip install 'polars[pyarrow]' sqlalchemy-cratedb
68+
```
69+
70+
:::{rubric} Synopsis
71+
:::
72+
73+
Write Polars dataframe to CrateDB.
74+
75+
`example.py`
76+
```python
77+
import polars as pl
78+
import sqlalchemy as sa
79+
from sqlalchemy_cratedb import insert_bulk
80+
81+
CRATEDB_URI = "crate://crate:crate@localhost:4200"
82+
TABLE_NAME = "example"
83+
84+
df = pl.from_pandas(makeTimeDataFrame(rows=500_000, freq="s"))
85+
engine = sa.create_engine(CRATEDB_URI)
86+
df.write_database(
87+
engine="sqlalchemy",
88+
connection=engine,
89+
table_name=TABLE_NAME,
90+
if_table_exists="replace",
91+
engine_options={
92+
"method": insert_bulk,
93+
"chunksize": 20_000,
94+
},
95+
)
96+
```
97+
98+
:::{rubric} Quickstart example
99+
:::
100+
101+
Create the file `example.py` including the synopsis code shared above.
102+
Complete the example by using the `makeTimeDataFrame()` function.
103+
104+
:::{literalinclude} ../pandas/makeTimeDataFrame.py
105+
:::
106+
107+
:::{include} /connect/_cratedb.md
108+
:::
109+
```shell
110+
pip install 'polars[pyarrow]' sqlalchemy-cratedb pandas
111+
python example.py
112+
```
113+
114+
:::{rubric} Full example
115+
:::
116+
117+
:::{card}
118+
:link: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/polars
119+
:link-type: url
120+
{material-regular}`play_arrow;2em`
121+
Connect to CrateDB and CrateDB Cloud using Polars.
122+
+++
123+
Includes basic examples of how to use Polars with CrateDB.
124+
:::
59125

60126

61127
[Apache Arrow]: https://arrow.apache.org/
62128
[Polars]: https://pola.rs/
63-
[Polars code examples]: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/polars

docs/integrate/status.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ on behalf of [cratedb-examples] and [academy-fundamentals-course].
6060
<img src="https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-dask.yml?branch=main&label=Dask" loading="lazy"></a>
6161
<a href="https://github.com/crate/cratedb-examples/actions/workflows/dataframe-pandas.yml" target="_blank">
6262
<img src="https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-pandas.yml?branch=main&label=pandas" loading="lazy"></a>
63+
<a href="https://github.com/crate/cratedb-examples/actions/workflows/dataframe-polars.yml" target="_blank">
64+
<img src="https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-polars.yml?branch=main&label=Polars" loading="lazy"></a>
6365
</td>
6466
</tr>
6567

0 commit comments

Comments
 (0)