Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce pre-commit. #617

Merged
merged 11 commits into from
Jan 4, 2024
4 changes: 2 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ coverage:
# Total project must not drop by more than 3%
target: auto
threshold: "3%"

patch:
default:
# Patch coverage must be 92%
target: auto
threshold: "92%"

precision: 2
round: down
range: 70...98
Expand Down
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Code of Conduct

Please see [`docs/conduct.md`](../docs/conduct.rst)
Please see [`docs/conduct.md`](docs/conduct.rst)
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jobs:
test:
defaults:
defaults:
run:
shell: bash -el {0}
strategy:
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
with:
files: "**/test-*.xml"
docs:
defaults:
defaults:
run:
shell: bash -el {0}
runs-on: ubuntu-latest
Expand Down
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: fix-byte-order-marker
- id: destroyed-symlinks
- id: fix-encoding-pragma
args: ["--remove"]
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: no-commit-to-branch
- id: pretty-format-json
args: ["--autofix", "--no-ensure-ascii"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
hooks:
- id: ruff
args: ["--fix"]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ python:
- method: pip
path: .
extra_requirements:
- docs
- docs
18 changes: 9 additions & 9 deletions asv.conf.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": 1,
"project": "sparse",
"project_url": "https://sparse.pydata.org/",
"repo": ".",
"dvcs": "git",
"environment_type": "conda",
"env_dir": ".asv/env",
"results_dir": ".asv/results",
"html_dir": ".asv/html"
"dvcs": "git",
"env_dir": ".asv/env",
"environment_type": "conda",
"html_dir": ".asv/html",
"project": "sparse",
"project_url": "https://sparse.pydata.org/",
"repo": ".",
"results_dir": ".asv/results",
"version": 1
}
4 changes: 2 additions & 2 deletions benchmarks/benchmark_coo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

import sparse

import numpy as np


class MatrixMultiplySuite:
def setup(self):
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmark_gcxs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

import sparse

import numpy as np


class MatrixMultiplySuite:
def setup(self):
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/benchmark_matmul.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import sparse

import numpy as np


class Matmul_Sparse:
params = (["coo", "gcxs"], [0, 1, None])
Expand Down
7 changes: 3 additions & 4 deletions benchmarks/benchmark_tensordot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import sparse

import numpy as np


class TensordotSuiteDenseSparse:
"""
Expand Down Expand Up @@ -32,9 +33,7 @@ def setup(self):
self.s2 = sparse.random((100, 100, 100, 100), density=0.01)

def time_dense(self):
sparse.tensordot(
self.s1, self.s2, axes=([0, 1], [0, 2]), return_type=np.ndarray
)
sparse.tensordot(self.s1, self.s2, axes=([0, 1], [0, 2]), return_type=np.ndarray)

def time_sparse(self):
sparse.tensordot(self.s1, self.s2, axes=([0, 1], [0, 2]))
Expand Down
9 changes: 2 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# sparse documentation build configuration file, created by
# sphinx-quickstart on Fri Dec 29 20:58:03 2017.
Expand Down Expand Up @@ -49,9 +48,7 @@
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

mathjax_path = (
"https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
)
mathjax_path = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
Expand Down Expand Up @@ -154,9 +151,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "sparse.tex", "sparse Documentation", "Sparse Developers", "manual")
]
latex_documents = [(master_doc, "sparse.tex", "sparse Documentation", "Sparse Developers", "manual")]

# -- Options for manual page output ---------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/construct.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ DOK arrays also support fancy indexing assignment if and only if all dimensions

Alongside indexing assignment and retrieval, :obj:`DOK` arrays support any arbitrary broadcasting function
to any number of arguments where the arguments can be :obj:`SparseArray` objects, :obj:`scipy.sparse.spmatrix`
objects, or :obj:`numpy.ndarrays`.
objects, or :obj:`numpy.ndarrays`.

.. code-block:: python

Expand All @@ -161,7 +161,7 @@ and return a new boolean :obj:`DOK` array.
y = np.random.random((10, 10))
x == y

:obj:`DOK` arrays are returned from elemwise functions and standard ufuncs if and only if all
:obj:`DOK` arrays are returned from elemwise functions and standard ufuncs if and only if all
:obj:`SparseArray` objects are obj:`DOK` arrays. Otherwise, a :obj:`COO` array or dense array are returned.

At the end, you can convert the :obj:`DOK` array to a :obj:`COO` arrays.
Expand Down
13 changes: 4 additions & 9 deletions docs/gen_logo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import xml.etree.ElementTree as et

import numpy as np


Expand Down Expand Up @@ -62,9 +63,7 @@ def fill(rs):
root,
"rect",
style=f"{colors['orange']};{fill(rs)};",
transform=transform(
1, b, 0, 1, (i + 5) * s + offset_x, (i * b + j) * s + offset_y
),
transform=transform(1, b, 0, 1, (i + 5) * s + offset_x, (i * b + j) * s + offset_y),
**kwargs,
)

Expand Down Expand Up @@ -104,9 +103,7 @@ def fill(rs):
root,
"rect",
style=f"{colors['blue']};{fill(rs)};",
transform=transform(
1, b, 0, 1, i * s + offset_x, (i * b + j + y2) * s + offset_y
),
transform=transform(1, b, 0, 1, i * s + offset_x, (i * b + j + y2) * s + offset_y),
**kwargs,
)

Expand All @@ -122,9 +119,7 @@ def fill(rs):
root,
"rect",
style=f"{colors['grey']};{fill(rs)};",
transform=transform(
1, -b, 0, 1, (i + 5) * s + offset_x, ((10 - i) * b + j + 5) * s + offset_y
),
transform=transform(1, -b, 0, 1, (i + 5) * s + offset_x, ((10 - i) * b + j + 5) * s + offset_y),
**kwargs,
)

Expand Down
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.T.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.T

.. currentmodule:: sparse

.. autoattribute:: COO.T
.. autoattribute:: COO.T
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.all.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO.all

.. currentmodule:: sparse

.. automethod:: COO.all
.. automethod:: COO.all
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.any.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO.any

.. currentmodule:: sparse

.. automethod:: COO.any
.. automethod:: COO.any
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.asformat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO.asformat

.. currentmodule:: sparse

.. automethod:: COO.asformat
.. automethod:: COO.asformat
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.astype.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.astype

.. currentmodule:: sparse

.. automethod:: COO.astype
.. automethod:: COO.astype
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.broadcast_to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.broadcast\_to

.. currentmodule:: sparse

.. automethod:: COO.broadcast_to
.. automethod:: COO.broadcast_to
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.dot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.dot

.. currentmodule:: sparse

.. automethod:: COO.dot
.. automethod:: COO.dot
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.dtype.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.dtype

.. currentmodule:: sparse

.. autoattribute:: COO.dtype
.. autoattribute:: COO.dtype
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.enable_caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.enable\_caching

.. currentmodule:: sparse

.. automethod:: COO.enable_caching
.. automethod:: COO.enable_caching
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.flatten.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO.flatten

.. currentmodule:: sparse

.. automethod:: COO.flatten
.. automethod:: COO.flatten
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.from_iter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO.from\_iter

.. currentmodule:: sparse

.. automethod:: COO.from_iter
.. automethod:: COO.from_iter
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.from_numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.from\_numpy

.. currentmodule:: sparse

.. automethod:: COO.from_numpy
.. automethod:: COO.from_numpy
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.from_scipy_sparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.from\_scipy\_sparse

.. currentmodule:: sparse

.. automethod:: COO.from_scipy_sparse
.. automethod:: COO.from_scipy_sparse
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.linear_loc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.linear\_loc

.. currentmodule:: sparse

.. automethod:: COO.linear_loc
.. automethod:: COO.linear_loc
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.max.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.max

.. currentmodule:: sparse

.. automethod:: COO.max
.. automethod:: COO.max
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.maybe_densify.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.maybe\_densify

.. currentmodule:: sparse

.. automethod:: COO.maybe_densify
.. automethod:: COO.maybe_densify
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.min

.. currentmodule:: sparse

.. automethod:: COO.min
.. automethod:: COO.min
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.nbytes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.nbytes

.. currentmodule:: sparse

.. autoattribute:: COO.nbytes
.. autoattribute:: COO.nbytes
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.ndim.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.ndim

.. currentmodule:: sparse

.. autoattribute:: COO.ndim
.. autoattribute:: COO.ndim
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.nnz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.nnz

.. currentmodule:: sparse

.. autoattribute:: COO.nnz
.. autoattribute:: COO.nnz
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.nonzero.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO.nonzero

.. currentmodule:: sparse

.. automethod:: COO.nonzero
.. automethod:: COO.nonzero
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.prod.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.prod

.. currentmodule:: sparse

.. automethod:: COO.prod
.. automethod:: COO.prod
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.reduce.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.reduce

.. currentmodule:: sparse

.. automethod:: COO.reduce
.. automethod:: COO.reduce
2 changes: 1 addition & 1 deletion docs/generated/sparse.COO.reshape.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COO\.reshape

.. currentmodule:: sparse

.. automethod:: COO.reshape
.. automethod:: COO.reshape
Loading
Loading