Skip to content

Commit

Permalink
style: ruff-formats (GalacticDynamics#162)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Feb 27, 2024
1 parent fa0806c commit f6998dd
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
11 changes: 4 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
[tool.hatch]
build.hooks.vcs.version-file = "src/galax/_version.py"
envs.default.dependencies = ["pytest", "pytest-cov"]
version.source = "vcs"
metadata.allow-direct-references = true
version.source = "vcs"


[tool.pytest.ini_options]
Expand Down Expand Up @@ -173,7 +173,7 @@
"F722", # Syntax error in forward annotation <- jaxtyping
"F821", # undefined name <- jaxtyping
"FIX002", # Line contains TODO, consider resolving the issue
"ISC001", # single-line-implicit-string-concatenation <- ruff-format
"ISC001", # Implicit string concatenation <- ruff-format
"N80", # Naming conventions.
"PD", # pandas-vet
"PLR", # Design related pylint codes
Expand All @@ -182,11 +182,6 @@
"TD002", # Missing author in TODO
"TD003", # Missing issue link on the line following this TODO
"UP037", # Remove quote from type annotation <- jaxtyping
# TODO: fix these
"ARG001",
"ARG002",
"ERA001", # commented-out code
"F841",
]
# Uncomment if using a _compat.typing backport
# typing-modules = ["galax._compat.typing"]
Expand All @@ -202,6 +197,8 @@
"noxfile.py" = ["ERA001", "T20"]
"tests/**" = [
"ANN",
"ARG001",
"ARG002",
"D10",
"E731",
"INP001",
Expand Down
3 changes: 2 additions & 1 deletion src/galax/coordinates/_psp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Shaped(Protocol):


def _getitem_broadscalartime_index_tuple(
index: tuple[Any, ...], t: FloatArrayAnyShape
index: tuple[Any, ...],
t: FloatArrayAnyShape, # noqa: ARG001
) -> Any:
"""Get the time index from a slice."""
if len(index) == 0: # slice is an empty tuple
Expand Down
7 changes: 6 additions & 1 deletion src/galax/potential/_potential/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ def tidal_tensor(
# Integrating orbits

@partial(jax.jit)
def _integrator_F(self, t: FloatScalar, w: Vec6, args: tuple[Any, ...]) -> Vec6:
def _integrator_F(
self,
t: FloatScalar,
w: Vec6,
args: tuple[Any, ...], # noqa: ARG002
) -> Vec6:
"""Return the derivative of the phase-space position."""
return jnp.hstack([w[3:6], self.acceleration(w[0:3], t).value]) # v, a

Expand Down
5 changes: 4 additions & 1 deletion src/galax/potential/_potential/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class NullPotential(AbstractPotential):

@partial(jax.jit)
def _potential_energy(
self, q: BatchVec3, /, t: BatchableFloatOrIntScalarLike
self,
q: BatchVec3,
/,
t: BatchableFloatOrIntScalarLike, # noqa: ARG002
) -> BatchFloatScalar:
return xp.zeros(q.shape[:-1], dtype=q.dtype)
2 changes: 1 addition & 1 deletion src/galax/potential/_potential/io/gala_noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
_GALA_TO_GALAX_REGISTRY: dict["type[GalaPotentialBase]", type[AbstractPotential]] = {}


def gala_to_galax(pot: "GalaPotentialBase", /) -> AbstractPotentialBase:
def gala_to_galax(pot: "GalaPotentialBase", /) -> AbstractPotentialBase: # noqa: ARG001
"""Convert a :mod:`gala` potential to a :mod:`galax` potential.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion src/galax/potential/_potential/param/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _call_helper(self, _: FloatOrIntScalar) -> FloatArrayAnyShape:

@partial(jax.jit)
def __call__(
self, t: BatchableFloatOrIntScalarLike = 0, **kwargs: Any
self, t: BatchableFloatOrIntScalarLike = 0, **_: Any
) -> FloatArrayAnyShape:
"""Return the constant parameter value.
Expand Down
2 changes: 1 addition & 1 deletion src/galax/potential/_potential/param/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __set__(
# Convert
if isinstance(value, AbstractParameter):
# TODO: this doesn't handle the correct output unit, a. la.
# potential.units[self.dimensions]
# ``potential.units[self.dimensions]``
# Check the unit is compatible
self._check_unit(potential, value.unit)
elif callable(value):
Expand Down
18 changes: 10 additions & 8 deletions src/galax/potential/_potential/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _from_usys(value: UnitSystem, /) -> UnitSystem:


@converter_to_usys.register
def _from_none(value: None, /) -> UnitSystem:
def _from_none(_: None, /) -> UnitSystem:
return dimensionless


Expand Down Expand Up @@ -86,7 +86,7 @@ def convert_inputs_to_arrays(


@singledispatch
def convert_input_to_array(value: Any, /, *, units: UnitSystem, **kwargs: Any) -> Any:
def convert_input_to_array(value: Any, /, *, units: UnitSystem, **_: Any) -> Any:
"""Parse input arguments.
This function uses :func:`~functools.singledispatch` to dispatch on the type
Expand Down Expand Up @@ -114,21 +114,23 @@ def convert_input_to_array(value: Any, /, *, units: UnitSystem, **kwargs: Any) -
@convert_input_to_array.register(float)
@convert_input_to_array.register(Array)
def _convert_from_arraylike(
value: Value, /, *, units: UnitSystem, **kwargs: Any
value: Value,
/,
*,
units: UnitSystem, # noqa: ARG001
**_: Any,
) -> Array:
return xp.asarray(value)


@convert_input_to_array.register(Quantity)
def _convert_from_quantity(
value: Quantity, /, *, units: UnitSystem, **kwargs: Any
) -> Array:
def _convert_from_quantity(value: Quantity, /, *, units: UnitSystem, **_: Any) -> Array:
return xp.asarray(value.decompose(units).value)


@convert_input_to_array.register(BaseRepresentationOrDifferential)
def _convert_from_baserep(
value: BaseRepresentationOrDifferential, /, *, units: UnitSystem, **kwargs: Any
value: BaseRepresentationOrDifferential, /, *, units: UnitSystem, **_: Any
) -> Array:
return xp.stack(
[getattr(value, attr).decompose(units).value for attr in value.components]
Expand Down Expand Up @@ -171,6 +173,6 @@ def _from_gala(value: GalaUnitSystem, /) -> UnitSystem:

@converter_to_usys.register
def _from_gala_dimensionless(
value: GalaDimensionlessUnitSystem, /
_: GalaDimensionlessUnitSystem, /
) -> DimensionlessUnitSystem:
return dimensionless
2 changes: 1 addition & 1 deletion tests/unit/coordinates/psp/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_w(self, w: T) -> None:
# Check existence
assert hasattr(w, "w")

# units != None
# units are not None
assert w.w(units=galactic).shape[:-1] == w.full_shape[:-1]

# ==========================================================================
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/coordinates/psp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_shaped_nd(self, t2x3: Vec2x3) -> None:
index = jnp.array([True, False])
assert jnp.array_equal(self.get_index(index, t2x3), index)

# index.shape == t.shape
# index.shape equals t.shape
index = jnp.array([[True, False], [False, True]])
assert jnp.array_equal(self.get_index(index, t2x3), index)

Expand Down Expand Up @@ -175,9 +175,5 @@ def test_shaped_nd(self, t2x3: Vec2x3) -> None:
assert jnp.array_equal(self.get_index(index, t2x3), index)

index = jnp.array([[True, False], [False, True]])
msg = (
f"Index {index} has too many dimensions for "
f"time array of shape {t2x3.shape}"
)
with pytest.raises(IndexError):
self.get_index(index, t2x3)

0 comments on commit f6998dd

Please sign in to comment.