Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
- name: Install xarray_sql
run: uv sync --dev
- name: Run unit tests
run: uv run pytest -m "not integration"
run: uv run pytest -m "not integration"
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ jobs:
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Lint with pyink
run: uvx pyink --check .
- name: Run pre-commit (with uvx)
run: uvx pre-commit run --all-files
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
verbose: true
verbose: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ dist
__pycache__
.pytest_cache
.venv
.idea
.idea
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-json
- id: check-toml

- repo: https://github.com/google/pyink
rev: 24.10.1
hooks:
- id: pyink
# Configuration is read from pyproject.toml [tool.pyink]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this comment.


- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies: [types-setuptools]
args: [--ignore-missing-imports]
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11
3.11
16 changes: 12 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@ reading [Xarray's contributing guide](https://docs.xarray.dev/en/stable/contribu
0. We use `uv` to manage the project: https://docs.astral.sh/uv/getting-started/installation/
1. Clone the repository (bonus: [via SSH](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account))
and `cd xarray_sql` (the project root).
2. Install dev dependencies via: `uv sync --dev`
2. Install dev dependencies via: `uv sync --dev`
3. Install pre-commit hooks: `uv run pre-commit install`

This will automatically run code formatting (pyink) and type checking (mypy) before each commit.
You can also run the hooks manually with: `uv run pre-commit run --all-files`


## Before submitting a pull request...

Thanks so much for your contribution! For a volunteer led project, we so
appreciate your help. A few things to keep in mind:
- Please be nice. We assume good intent from you, and we ask you to do the same for us.
- Development in this project will be slow if not sporadic. Reviews will come
- Development in this project will be slow if not sporadic. Reviews will come
as time allows.
- Every contribution, big or small, matters and deserves credit.
- Every contribution, big or small, matters and deserves credit.

Here are a few requests for your development process:
- We require all code to be formatted with `pyink` (i.e., please run `uvx pyink .`).
- We require all code to be formatted with `pyink` and type-checked with `mypy`.
These checks run automatically via pre-commit hooks (see Developer setup above).
If you need to run them manually:
- Formatting: `uv run pre-commit run pyink --all-files` or `uvx pyink .`
- Type checking: `uv run pre-commit run mypy --all-files` or `uv run mypy xarray_sql/`
- Please include unit tests, if possible, and performance tests when you touch the core functionality (see `perf_tests/`).
- It's polite to do a self review before asking for one from a maintainer. Don't stress if you forget; we all do sometimes.
- Please add (or update) documentation when adding new code. We use [Google Style docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ ctx.from_dataset('air', ds, chunks=dict(time=24)) # the dataset needs to be chu
result = ctx.sql('''
SELECT
"lat", "lon", AVG("air") as air_total
FROM
"air"
FROM
"air"
GROUP BY
"lat", "lon"
''')
Expand All @@ -63,7 +63,7 @@ result = ctx.sql('''
# | 72.5 | 275.0 | 257.30633219178037 |
# +------+-------+--------------------+
# Data truncated.
#
#

# A table of the average temperature for each location across time.
df = result.to_pandas()
Expand Down Expand Up @@ -104,7 +104,7 @@ All chunks in a Xarray Dataset are transformed into a Dask DataFrame via
`from_map()` and `to_dataframe()`. For SQL support, we just use `dask-sql`.
That's it!

_2025 update_: This library now implements a Dask-like `from_map` interface in
_2025 update_: This library now implements a Dask-like `from_map` interface in
pure DataFusion and PyArrow, but works with the same principle!

## Why does this work?
Expand All @@ -113,13 +113,13 @@ Underneath Xarray, Dask, and Pandas, there are NumPy arrays. These are paged in
chunks and represented contiguously in memory. It is only a matter of metadata
that breaks them up into ndarrays. `to_dataframe()`
just changes this metadata (via a `ravel()`/`reshape()`), back into a column
amenable to a DataFrame. We take advantage of this light weight metadata change to
amenable to a DataFrame. We take advantage of this light weight metadata change to
make chunked information scannable by a DB engine (DataFusion).

## What are the current limitations?

_2025 update_: TBD, DataFusion provides a whole new world! Currently, we're looking for
early users – "tire kickers", if you will. We'd love your input to shape the direction of this
early users – "tire kickers", if you will. We'd love your input to shape the direction of this
project! Please, give this a try and [file issues](https://github.com/alxmrs/xarray-sql/issues) as
you see fit. Check out our [contributing guide](CONTRIBUTING.md), too 😉.

Expand Down
3 changes: 1 addition & 2 deletions perf_tests/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Performance testing & profiling

So far, this includes statistical profiles via py-spy.
So far, this includes statistical profiles via py-spy.

## Dev Process

Expand All @@ -16,4 +16,3 @@ So far, this includes statistical profiles via py-spy.
2. After tuning code in xarray-sql, run another profile to generate a SVG.

3. Please commit the "after" profile SVG along with the performance improvements.

4 changes: 2 additions & 2 deletions perf_tests/groupby_air.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"""
SELECT
"lat", "lon", SUM("air") as air_total
FROM
"air"
FROM
"air"
GROUP BY
"lat", "lon"
"""
Expand Down
4 changes: 2 additions & 2 deletions perf_tests/groupby_air_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"""
SELECT
"lat", "lon", SUM("air") as air_total
FROM
"air"
FROM
"air"
GROUP BY
"lat", "lon"
"""
Expand Down
2 changes: 1 addition & 1 deletion perf_tests/profile.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
py-spy record ./$1 --function --threads
py-spy record ./$1 --function --threads
26 changes: 25 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,35 @@ preview = true
pyink-indentation = 2
pyink-use-majority-quotes = true

[tool.mypy]
python_version = "3.11"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = false
follow_imports = "skip"
exclude = [
"perf_tests/",
"xarray_sql.egg-info/",
"^\\.venv/",
]

# Per-module ignores for libraries without type stubs
[[tool.mypy.overrides]]
module = [
"pyarrow.*",
"datafusion.*",
"xarray.*",
]
ignore_missing_imports = true

[tool.setuptools_scm]

[dependency-groups]
dev = [
"xarray_sql[test]",
"py-spy>=0.4.0",
"pyink>=24.10.1",
]
"mypy>=1.11.0",
"pre-commit>=3.0.0",
"pandas-stubs>=2.2.2.240807",
]
Loading