Skip to content

Commit fa436e8

Browse files
Add pre-commit hooks with pyink and mypy (#91)
This commit sets up automated code quality checks using pre-commit: 1. Pre-commit configuration (.pre-commit-config.yaml): - Added pyink for code formatting (reads config from pyproject.toml) - Added mypy for type checking - Added standard pre-commit hooks (trailing whitespace, end-of-file, etc.) 2. Updated pyproject.toml: - Added mypy and pre-commit to dev dependencies - Added pandas-stubs for better type checking - Configured mypy with per-module ignores for libraries without stubs - Set python_version to 3.11 to match .python-version file 3. Fixed type errors in xarray_sql/df.py: - Fixed tuple concatenation type issues in block_slices() - Fixed Callable type annotation syntax in from_map_batched() - Added type ignore for xarray return type in pivot() 4. Updated CONTRIBUTING.md: - Documented pre-commit setup steps - Updated formatting/type-checking instructions 5. Updated GitHub Actions lint workflow: - Added mypy type checking step - Changed to use uv run for consistency 6. Auto-fixed formatting issues: - Removed trailing whitespace - Fixed end-of-file newlines - Applied pyink formatting All hooks pass successfully and type checking works correctly. --------- Co-authored-by: jayendra <jayendra0parmar@gmail.com>
1 parent 7414128 commit fa436e8

16 files changed

Lines changed: 1953 additions & 1641 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
- name: Install xarray_sql
4949
run: uv sync --dev
5050
- name: Run unit tests
51-
run: uv run pytest -m "not integration"
51+
run: uv run pytest -m "not integration"

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ jobs:
3939
uses: astral-sh/setup-uv@v5
4040
with:
4141
python-version: ${{ matrix.python-version }}
42-
- name: Lint with pyink
43-
run: uvx pyink --check .
42+
- name: Run pre-commit (with uvx)
43+
run: uvx pre-commit run --all-files

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ jobs:
9494
with:
9595
user: __token__
9696
password: ${{ secrets.PYPI_TOKEN }}
97-
verbose: true
97+
verbose: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ dist
55
__pycache__
66
.pytest_cache
77
.venv
8-
.idea
8+
.idea

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-json
10+
- id: check-toml
11+
12+
- repo: https://github.com/google/pyink
13+
rev: 24.10.1
14+
hooks:
15+
- id: pyink
16+
# Configuration is read from pyproject.toml [tool.pyink]
17+
18+
- repo: https://github.com/pre-commit/mirrors-mypy
19+
rev: v1.11.2
20+
hooks:
21+
- id: mypy
22+
additional_dependencies: [types-setuptools]
23+
args: [--ignore-missing-imports]

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.11

CONTRIBUTING.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ reading [Xarray's contributing guide](https://docs.xarray.dev/en/stable/contribu
1515
0. We use `uv` to manage the project: https://docs.astral.sh/uv/getting-started/installation/
1616
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))
1717
and `cd xarray_sql` (the project root).
18-
2. Install dev dependencies via: `uv sync --dev`
18+
2. Install dev dependencies via: `uv sync --dev`
19+
3. Install pre-commit hooks: `uv run pre-commit install`
20+
21+
This will automatically run code formatting (pyink) and type checking (mypy) before each commit.
22+
You can also run the hooks manually with: `uv run pre-commit run --all-files`
1923

2024

2125
## Before submitting a pull request...
2226

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

3034
Here are a few requests for your development process:
31-
- We require all code to be formatted with `pyink` (i.e., please run `uvx pyink .`).
35+
- We require all code to be formatted with `pyink` and type-checked with `mypy`.
36+
These checks run automatically via pre-commit hooks (see Developer setup above).
37+
If you need to run them manually:
38+
- Formatting: `uv run pre-commit run pyink --all-files` or `uvx pyink .`
39+
- Type checking: `uv run pre-commit run mypy --all-files` or `uv run mypy xarray_sql/`
3240
- Please include unit tests, if possible, and performance tests when you touch the core functionality (see `perf_tests/`).
3341
- 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.
3442
- Please add (or update) documentation when adding new code. We use [Google Style docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,4 @@
199199
distributed under the License is distributed on an "AS IS" BASIS,
200200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201201
See the License for the specific language governing permissions and
202-
limitations under the License.
202+
limitations under the License.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ ctx.from_dataset('air', ds, chunks=dict(time=24)) # the dataset needs to be chu
4242
result = ctx.sql('''
4343
SELECT
4444
"lat", "lon", AVG("air") as air_total
45-
FROM
46-
"air"
45+
FROM
46+
"air"
4747
GROUP BY
4848
"lat", "lon"
4949
''')
@@ -63,7 +63,7 @@ result = ctx.sql('''
6363
# | 72.5 | 275.0 | 257.30633219178037 |
6464
# +------+-------+--------------------+
6565
# Data truncated.
66-
#
66+
#
6767

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

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

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

119119
## What are the current limitations?
120120

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

perf_tests/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Performance testing & profiling
22

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

55
## Dev Process
66

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

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

0 commit comments

Comments
 (0)