Skip to content

Commit a63d083

Browse files
committed
revert branch UNPICK
1 parent ed4ad0b commit a63d083

File tree

15 files changed

+146
-415
lines changed

15 files changed

+146
-415
lines changed

AGENTS.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# AGENTS Instructions
2+
3+
This repository contains Python bindings for Rust's DataFusion.
4+
5+
## Development workflow
6+
- Ensure git submodules are initialized: `git submodule update --init`.
7+
- Build the Rust extension before running tests:
8+
- `uv run --no-project maturin develop --uv`
9+
- Run tests with pytest:
10+
- `uv --no-project pytest .`
11+
12+
## Linting and formatting
13+
- Use pre-commit for linting/formatting.
14+
- Run hooks for changed files before committing:
15+
- `pre-commit run --files <files>`
16+
- or `pre-commit run --all-files`
17+
- Hooks enforce:
18+
- Python linting/formatting via Ruff
19+
- Rust formatting via `cargo fmt`
20+
- Rust linting via `cargo clippy`
21+
22+
## Notes
23+
- The repository mixes Python and Rust; ensure changes build for both languages.
24+
- If adding new dependencies, update `pyproject.toml` and run `uv sync --dev --no-install-package datafusion`.
25+
26+
## Helper Functions
27+
- `python/datafusion/io.py` offers global context readers:
28+
- `read_parquet`
29+
- `read_json`
30+
- `read_csv`
31+
- `read_avro`
32+
- `python/datafusion/user_defined.py` exports convenience creators for user-defined functions:
33+
- `udf` (scalar)
34+
- `udaf` (aggregate)
35+
- `udwf` (window)
36+
- `udtf` (table)
37+
- `python/datafusion/col.py` exposes the `Col` helper with `col` and `column` instances for building column expressions using attribute access.
38+
- `python/datafusion/catalog.py` provides Python-based catalog and schema providers.
39+
- `python/datafusion/object_store.py` exposes object store connectors: `AmazonS3`, `GoogleCloud`, `MicrosoftAzure`, `LocalFileSystem`, and `Http`.
40+
- `python/datafusion/unparser.py` converts logical plans back to SQL via the `Dialect` and `Unparser` classes.
41+
- `python/datafusion/dataframe_formatter.py` offers configurable HTML and string formatting for DataFrames (replaces the deprecated `html_formatter.py`).
42+
- `python/tests/generic.py` includes utilities for test data generation:
43+
- `data`
44+
- `data_with_nans`
45+
- `data_datetime`
46+
- `data_date32`
47+
- `data_timedelta`
48+
- `data_binary_other`
49+
- `write_parquet`
50+
- `python/tests/conftest.py` defines reusable pytest fixtures:
51+
- `ctx` creates a `SessionContext`.
52+
- `database` registers a sample CSV dataset.
53+
- `src/dataframe.rs` provides the `collect_record_batches_to_display` helper to fetch the first non-empty record batch and flag if more are available.

Cargo.lock

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ uuid = { version = "1.18", features = ["v4"] }
4848
mimalloc = { version = "0.1", optional = true, default-features = false, features = ["local_dynamic_tls"] }
4949
async-trait = "0.1.89"
5050
futures = "0.3"
51-
rayon = "1.10"
5251
object_store = { version = "0.12.3", features = ["aws", "gcp", "azure", "http"] }
5352
url = "2"
5453
log = "0.4.27"

benchmarks/collect_gil_bench.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/source/user-guide/configuration.rst

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,5 @@ a :py:class:`~datafusion.context.SessionConfig` and :py:class:`~datafusion.conte
4747
print(ctx)
4848
4949
50-
.. _target_partitions:
51-
52-
Target partitions and threads
53-
-----------------------------
54-
55-
The :py:meth:`~datafusion.context.SessionConfig.with_target_partitions` method
56-
controls how many partitions DataFusion uses when executing a query. Each
57-
partition is processed on its own thread, so this setting effectively limits
58-
the number of threads that will be scheduled.
59-
60-
For most workloads a good starting value is the number of logical CPU cores on
61-
your machine. You can use :func:`os.cpu_count` to automatically configure this::
62-
63-
import os
64-
config = SessionConfig().with_target_partitions(os.cpu_count())
65-
66-
Choosing a value significantly higher than the available cores can lead to
67-
excessive context switching without performance gains, while a much lower value
68-
may underutilize the machine.
69-
70-
7150
You can read more about available :py:class:`~datafusion.context.SessionConfig` options in the `rust DataFusion Configuration guide <https://arrow.apache.org/datafusion/user-guide/configs.html>`_,
7251
and about :code:`RuntimeEnvBuilder` options in the rust `online API documentation <https://docs.rs/datafusion/latest/datafusion/execution/runtime_env/struct.RuntimeEnvBuilder.html>`_.

docs/source/user-guide/dataframe/collect-gil.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/source/user-guide/dataframe/index.rst

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ The ``DataFrame`` class is the core abstraction in DataFusion that represents ta
2525
on that data. DataFrames provide a flexible API for transforming data through various operations such as
2626
filtering, projection, aggregation, joining, and more.
2727

28-
A DataFrame represents a logical plan that is lazily evaluated. The actual execution occurs only when
29-
terminal operations like ``collect()``, ``show()``, or ``to_pandas()`` are called. ``collect()`` loads
30-
all record batches into Python memory; for large results you may want to stream data instead using
31-
``execute_stream()`` or ``__arrow_c_stream__()``.
28+
A DataFrame represents a logical plan that is lazily evaluated. The actual execution occurs only when
29+
terminal operations like ``collect()``, ``show()``, or ``to_pandas()`` are called.
3230

3331
Creating DataFrames
3432
-------------------
@@ -130,47 +128,27 @@ DataFusion's DataFrame API offers a wide range of operations:
130128
131129
Terminal Operations
132130
-------------------
133-
``collect()`` materializes every record batch in Python. While convenient, this
134-
eagerly loads the full result set into memory and can overwhelm the Python
135-
process for large queries. Alternatives that stream data from Rust avoid this
136-
memory growth:
131+
132+
To materialize the results of your DataFrame operations:
137133

138134
.. code-block:: python
139135
140-
# Collect all data as PyArrow RecordBatches (loads entire result set)
136+
# Collect all data as PyArrow RecordBatches
141137
result_batches = df.collect()
142-
143-
# Stream batches using the native API
144-
stream = df.execute_stream()
145-
for batch in stream:
146-
... # process each RecordBatch
147-
148-
# Stream via the Arrow C Data Interface
149-
import pyarrow as pa
150-
reader = pa.ipc.RecordBatchStreamReader._import_from_c(df.__arrow_c_stream__())
151-
for batch in reader:
152-
...
153-
154-
# Convert to various formats (also load all data into memory)
138+
139+
# Convert to various formats
155140
pandas_df = df.to_pandas() # Pandas DataFrame
156141
polars_df = df.to_polars() # Polars DataFrame
157142
arrow_table = df.to_arrow_table() # PyArrow Table
158143
py_dict = df.to_pydict() # Python dictionary
159144
py_list = df.to_pylist() # Python list of dictionaries
160-
145+
161146
# Display results
162147
df.show() # Print tabular format to console
163-
148+
164149
# Count rows
165150
count = df.count()
166151
167-
For large outputs, prefer engine-level writers such as ``df.write_parquet()``
168-
or other DataFusion writers. These stream data directly to the destination and
169-
avoid buffering the entire dataset in Python.
170-
171-
For more on parallel record batch conversion and the Python GIL, see
172-
:doc:`collect-gil`.
173-
174152
HTML Rendering
175153
--------------
176154

@@ -229,4 +207,3 @@ For a complete list of available functions, see the :py:mod:`datafusion.function
229207
:maxdepth: 1
230208

231209
rendering
232-
collect-gil

docs/source/user-guide/io/arrow.rst

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,17 @@ and returns a ``StructArray``. Common pyarrow sources you can use are:
5757
Exporting from DataFusion
5858
-------------------------
5959

60-
DataFusion DataFrames implement ``__arrow_c_stream__`` so any Python library
61-
that accepts this interface can import a DataFusion ``DataFrame`` directly.
60+
DataFusion DataFrames implement ``__arrow_c_stream__`` PyCapsule interface, so any
61+
Python library that accepts these can import a DataFusion DataFrame directly.
6262

63-
``collect()`` or ``pa.table(df)`` will materialize every record batch in
64-
Python. For large results this can quickly exhaust memory. Instead, stream the
65-
output incrementally:
63+
.. warning::
64+
It is important to note that this will cause the DataFrame execution to happen, which may be
65+
a time consuming task. That is, you will cause a
66+
:py:func:`datafusion.dataframe.DataFrame.collect` operation call to occur.
6667

67-
.. ipython:: python
68-
69-
# Stream batches with DataFusion's native API
70-
stream = df.execute_stream()
71-
for batch in stream:
72-
... # process each RecordBatch as it arrives
73-
74-
.. ipython:: python
75-
76-
# Expose a C stream that PyArrow can consume lazily
77-
import pyarrow as pa
78-
reader = pa.ipc.RecordBatchStreamReader._import_from_c(df.__arrow_c_stream__())
79-
for batch in reader:
80-
... # process each batch without buffering the entire table
81-
82-
If the goal is simply to persist results, prefer engine-level writers such as
83-
``df.write_parquet()``. These writers stream data from Rust directly to the
84-
destination and avoid Python-side memory growth.
8568

8669
.. ipython:: python
8770
8871
df = df.select((col("a") * lit(1.5)).alias("c"), lit("df").alias("d"))
89-
pa.table(df) # loads all batches into memory
72+
pa.table(df)
9073

python/datafusion/context.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,7 @@ def with_batch_size(self, batch_size: int) -> SessionConfig:
161161
def with_target_partitions(self, target_partitions: int) -> SessionConfig:
162162
"""Customize the number of target partitions for query execution.
163163
164-
Each partition is processed on its own thread, so this value controls
165-
the degree of parallelism. A good starting point is the number of
166-
logical CPU cores on your machine, for example
167-
``SessionConfig().with_target_partitions(os.cpu_count())``.
168-
169-
See the :ref:`configuration guide <target_partitions>` for more
170-
discussion on choosing a value.
164+
Increasing partitions can increase concurrency.
171165
172166
Args:
173167
target_partitions: Number of target partitions.

0 commit comments

Comments
 (0)