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

chore: move to Ruff-format #2777

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 1 addition & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ repos:
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude_types: [svg]
- id: mixed-line-ending
Expand All @@ -21,11 +20,6 @@ repos:
- id: name-tests-test
args: ["--pytest-test-first"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.0
hooks:
- id: black

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
Expand All @@ -37,6 +31,7 @@ repos:
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
Expand Down Expand Up @@ -66,13 +61,6 @@ repos:
types: [file, python]
files: ^tests/


- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
hooks:
Expand Down
4 changes: 1 addition & 3 deletions dev/generate-kernel-signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,7 @@ def f(grid, block, args):
file.write(
""" f.dir = [{}]
out[{}] = f
""".format(
", ".join(dirlist), ", ".join(special)
)
""".format(", ".join(dirlist), ", ".join(special))
)
else:
file.write(
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ ignore_errors = true
ignore_missing_imports = true

[tool.ruff]
typing-modules = ["awkward._typing"]
src = ["src"]
extend-exclude = [
"studies",
Expand All @@ -266,9 +265,9 @@ extend-exclude = [
"docs-*",
"src/awkward/_typeparser/generated_parser.py",
]

[tool.ruff.lint]
select = [
"E", "F", "W", # flake8
extend-select = [
"B", "B904", # flake8-bugbear
"I", # isort
"C4", # flake8-comprehensions
Expand All @@ -294,11 +293,13 @@ ignore = [
"PLW2901", # Outer for loop variable overwritten by inner assignment target
"PLW0603", # Using the global statement to update is discouraged
"PLC1901", # x == "" can be simplified to not x (empty string is falsey)
"ISC001", # Conflicts with the formatter in 0.1.2
]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
]
typing-modules = ["awkward._typing"]
external = []
mccabe.max-complexity = 100

Expand Down
4 changes: 1 addition & 3 deletions src/awkward/_connect/numba/arrayview.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,7 @@ def add_statement(indent, name, arraytype, is_array):
"""
def contains_impl(obj, element):
{}
return False""".format(
"\n ".join(statements)
),
return False""".format("\n ".join(statements)),
"contains_impl",
)

Expand Down
13 changes: 5 additions & 8 deletions src/awkward/_nplikes/typetracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,14 +801,11 @@ def searchsorted(
try_touch_data(x)
try_touch_data(values)
try_touch_data(sorter)
if (
not (
is_unknown_length(x.size)
or sorter is None
or is_unknown_length(sorter.size)
)
and x.size != sorter.size
):
if not (
is_unknown_length(x.size)
or sorter is None
or is_unknown_length(sorter.size)
) and x.size != sorter.size:
raise ValueError("x.size should equal sorter.size")

return TypeTracerArray._new(x.dtype, (values.size,))
Expand Down
6 changes: 3 additions & 3 deletions src/awkward/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
)


JSONSerializable: TypeAlias = (
"str | int | float | bool | None | list | tuple | JSONMapping"
)
JSONSerializable: (
TypeAlias
) = "str | int | float | bool | None | list | tuple | JSONMapping"
henryiii marked this conversation as resolved.
Show resolved Hide resolved
JSONMapping: TypeAlias = "dict[str, JSONSerializable]"
7 changes: 4 additions & 3 deletions src/awkward/contents/regulararray.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ def _getitem_range(self, start: SupportsIndex, stop: IndexType) -> Content:
return self

zeros_length = index_nplike.index_as_shape_item(stop - start)
substart, substop = start * index_nplike.shape_item_as_index(
self._size
), stop * index_nplike.shape_item_as_index(self._size)
substart, substop = (
start * index_nplike.shape_item_as_index(self._size),
stop * index_nplike.shape_item_as_index(self._size),
)
return RegularArray(
self._content._getitem_range(substart, substop),
self._size,
Expand Down
6 changes: 2 additions & 4 deletions src/awkward/operations/ak_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def concatenate(arrays, axis=0, *, mergebool=True, highlevel=True, behavior=None
# Dispatch
if (
# Is an array with a known backend
backend_of(arrays, default=None)
is not None
backend_of(arrays, default=None) is not None
):
yield (arrays,)
else:
Expand All @@ -61,8 +60,7 @@ def _impl(arrays, axis, mergebool, highlevel, behavior):
# Simple single-array, axis=0 fast-path
if (
# Is an array with a known backend
backend_of(arrays, default=None)
is not None
backend_of(arrays, default=None) is not None
):
# Convert the array to a layout object
content = ak.operations.to_layout(
Expand Down
26 changes: 10 additions & 16 deletions tests/test_2682_custom_pickler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,19 @@ def test_default_pickler():


def test_noop_pickler(tmp_path):
assert (
pickle_complex_array_and_return_form(
"""
assert pickle_complex_array_and_return_form(
"""
def plugin(obj, protocol: int):
return NotImplemented""",
tmp_path,
)
== ak.forms.from_dict(
{"class": "ListOffsetArray", "offsets": "i64", "content": "int64"}
)
tmp_path,
) == ak.forms.from_dict(
{"class": "ListOffsetArray", "offsets": "i64", "content": "int64"}
)


def test_non_packing_pickler(tmp_path):
assert (
pickle_complex_array_and_return_form(
"""
assert pickle_complex_array_and_return_form(
"""
def plugin(obj, protocol):
import awkward as ak
if isinstance(obj, ak.Array):
Expand All @@ -92,11 +88,9 @@ def plugin(obj, protocol):
)
else:
return NotImplemented""",
tmp_path,
)
== ak.forms.from_dict(
{"class": "ListArray", "starts": "i64", "stops": "i64", "content": "int64"}
)
tmp_path,
) == ak.forms.from_dict(
{"class": "ListArray", "starts": "i64", "stops": "i64", "content": "int64"}
)


Expand Down