Skip to content

Commit

Permalink
Enable pydocstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-mue committed Oct 22, 2023
1 parent f2cbe35 commit fd3c386
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 16 deletions.
8 changes: 5 additions & 3 deletions geometer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ def free_indices(self) -> int:

@property
def tensor_shape(self) -> tuple[int, int]:
"""The shape or type of the tensor, the first number is the number of
covariant indices, the second the number of contravariant indices."""
"""The shape or type of the tensor.
The first number is the number of covariant indices, the second the number of contravariant indices.
"""
return len(self._covariant_indices), len(self._contravariant_indices)

@property
Expand Down Expand Up @@ -656,7 +659,6 @@ def add_edge(self, source: Tensor, target: Tensor) -> None:
TensorComputationError: If the tensors have no unused indices or the dimensions do not match.
"""

# First step: Find nodes if they are already in the diagram
source_index, target_index = None, None
for index, node in enumerate(self._nodes):
Expand Down
1 change: 0 additions & 1 deletion geometer/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def crossratio(
NotCollinear: If four points are supplied that are not collinear.
"""

if a == b:
return np.ones(a.shape[: a.free_indices])

Expand Down
3 changes: 1 addition & 2 deletions geometer/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,7 @@ def perpendicular(self, through: LineTensor) -> PlaneTensor:
...

def perpendicular(self, through: PointTensor | LineTensor) -> LineTensor | PlaneTensor:
"""Construct the perpendicular lines though the given points
or the perpendicular planes through the given lines.
"""Construct the perpendicular lines though the given points or the perpendicular planes through the given lines.
Only works for lines in 3D.
Expand Down
4 changes: 3 additions & 1 deletion geometer/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@


class PolytopeTensor(PointLikeTensor, ABC):
"""A class representing polytopes in arbitrary dimension. A (n+1)-polytope is a collection of n-polytopes that
"""A class representing polytopes in arbitrary dimension.
A (n+1)-polytope is a collection of n-polytopes that
have some (n-1)-polytopes in common, where 3-polytopes are polyhedra, 2-polytopes are polygons, 1-polytopes are
line segments and 0-polytopes are points.
Expand Down
3 changes: 1 addition & 2 deletions geometer/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ def __apply__(self, transformation: TransformationTensor) -> TransformationTenso

@classmethod
def from_points(cls, *args: tuple[PointTensor, PointTensor]) -> TransformationTensor:
"""Constructs a projective transformation in n-dimensional projective space from the image of n + 2 points in
general position.
"""Constructs a projective transformation in n-dimensional projective space from the image of n + 2 points in general position.
For two dimensional transformations, 4 pairs of points are required, of which no three points are collinear.
For three dimensional transformations, 5 pairs of points are required, of which no four points are coplanar.
Expand Down
10 changes: 5 additions & 5 deletions geometer/utils/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _sanitize_index_element(ind):


def sanitize_index(ind):
"""Sanitize the elements for indexing along one axis
"""Sanitize the elements for indexing along one axis.
>>> sanitize_index([2, 3, 5])
array([2, 3, 5])
Expand Down Expand Up @@ -73,7 +73,7 @@ def sanitize_index(ind):


def posify_index(shape, ind):
"""Flip negative indices around to positive ones
"""Flip negative indices around to positive ones.
>>> posify_index(10, 3)
3
Expand Down Expand Up @@ -101,7 +101,7 @@ def posify_index(shape, ind):


def replace_ellipsis(n, index):
"""Replace ... with slices, :, : ,:
"""Replace ... with slices, :, : ,:.
>>> replace_ellipsis(4, (3, Ellipsis, 2))
(3, slice(None, None, None), slice(None, None, None), 2)
Expand All @@ -120,12 +120,12 @@ def replace_ellipsis(n, index):


def normalize_index(idx, shape):
"""Normalize slicing indexes
"""Normalize slicing indexes.
1. Replaces ellipses with many full slices
2. Adds full slices to end of index
Examples
Examples:
--------
>>> normalize_index(1, (10,))
(1,)
Expand Down
2 changes: 2 additions & 0 deletions geometer/utils/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def orth(A: npt.ArrayLike, dim: int | None = None) -> npt.NDArray[np.number]:


class UFuncParameters(TypedDict, total=False):
"""Keyword parameters for numpy's ufuncs."""

where: npt.NDArray[np.bool_]
axes: list[tuple[int]]
axis: int
Expand Down
3 changes: 1 addition & 2 deletions geometer/utils/ops_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ def maybe_dispatch_ufunc_to_dunder_op(
*inputs: Any,
**kwargs: Any,
) -> Any:
"""
Dispatch a ufunc to the equivalent dunder method.
"""Dispatch a ufunc to the equivalent dunder method.
Args:
obj: The object whose dunder method we dispatch to.
Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ select = [
"PT", # flake8-pytest-style
"PL", # pylint
"RUF", # ruff-specific rules
"D", # pydocstyle
]
ignore = [
"E501", # line too long, handled by black
Expand All @@ -93,6 +94,14 @@ ignore = [
"PLR5501", # use `elif` instead of `else` then `if`, to reduce indentation
"PLR0124", # name compared with itself, required to check custom __eq__
"PLC0105", # type var naming according to variance
"D100", # Missing docstring in public module
"D101", # TODO: fix
"D102", # TODO: fix
"D103", # TODO: fix
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
"D417", # TODO: fix
]
unfixable = []
exclude = [
Expand All @@ -101,13 +110,17 @@ exclude = [

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"tests/**" = ["D"]

[tool.ruff.isort]
known-first-party = ["geometer"]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.pydocstyle]
convention = "google"

[tool.mypy]
plugins = ["numpy.typing.mypy_plugin"]
strict = true
Expand Down

0 comments on commit fd3c386

Please sign in to comment.