-
Notifications
You must be signed in to change notification settings - Fork 1
Chore/docstrings and overrides #139
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
Open
jc-macdonald
wants to merge
5
commits into
main
Choose a base branch
from
chore/docstrings-and-overrides
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2b0e4a6
docs: Google-style docstrings on undocumented private symbols
jc-macdonald 5a7a2fb
docs: runnable doctest examples on public API entry points
jc-macdonald 40bed4a
docs: complete Returns/Raises sections in new docstrings
jc-macdonald 2627645
refactor: extract helpers to drop 3 C901 overrides
jc-macdonald c07bd6d
style: ruff format compile.py after override removal
jc-macdonald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,20 @@ def _normalize_bracket_key(key: str) -> str: | |||||
|
|
||||||
|
|
||||||
| def _normalize_axis_name(ax_map: Mapping[str, Any], *, idx: int, seen: set[str]) -> str: | ||||||
| """Validate and return the ``name`` field of one axis definition. | ||||||
|
|
||||||
| Args: | ||||||
| ax_map: Raw axis mapping. | ||||||
| idx: Position in the surrounding ``axes`` list (for diagnostics). | ||||||
| seen: Mutable set of already-registered axis names; updated in place. | ||||||
|
|
||||||
| Returns: | ||||||
| The validated, stripped axis name. | ||||||
|
|
||||||
| Raises: | ||||||
| InvalidRhsSpecError: If ``name`` is missing, not a string, empty, or | ||||||
| duplicates an earlier axis. | ||||||
| """ | ||||||
| name_val = ax_map.get("name") | ||||||
| if not isinstance(name_val, str) or not name_val.strip(): | ||||||
| raise InvalidRhsSpecError(detail=f"axes[{idx}].name must be a non-empty string") | ||||||
|
|
@@ -64,6 +78,18 @@ def _normalize_axis_name(ax_map: Mapping[str, Any], *, idx: int, seen: set[str]) | |||||
|
|
||||||
|
|
||||||
| def _normalize_axis_type(ax_map: Mapping[str, Any], *, idx: int) -> str: | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Per the return type. May also make sense to convert this to a |
||||||
| """Validate and return the ``type`` field of one axis (default categorical). | ||||||
|
|
||||||
| Args: | ||||||
| ax_map: Raw axis mapping. | ||||||
| idx: Position in the surrounding ``axes`` list (for diagnostics). | ||||||
|
|
||||||
| Returns: | ||||||
| One of ``"categorical"``, ``"ordinal"``, or ``"continuous"``. | ||||||
|
|
||||||
| Raises: | ||||||
| InvalidRhsSpecError: If ``type`` is set to anything else. | ||||||
| """ | ||||||
| ax_type = str(ax_map.get("type", "categorical")).strip().lower() | ||||||
| if ax_type not in {"categorical", "ordinal", "continuous"}: | ||||||
| raise InvalidRhsSpecError( | ||||||
|
|
@@ -75,6 +101,19 @@ def _normalize_axis_type(ax_map: Mapping[str, Any], *, idx: int) -> str: | |||||
|
|
||||||
|
|
||||||
| def _normalize_axis_units(ax_map: Mapping[str, Any], *, idx: int) -> str | None: | ||||||
| """Validate and return the optional ``units`` field of one axis. | ||||||
|
|
||||||
| Args: | ||||||
| ax_map: Raw axis mapping. | ||||||
| idx: Position in the surrounding ``axes`` list (for diagnostics). | ||||||
|
|
||||||
| Returns: | ||||||
| Stripped units string or ``None`` when absent. | ||||||
|
|
||||||
| Raises: | ||||||
| InvalidRhsSpecError: If ``units`` is provided but is not a non-empty | ||||||
| string. | ||||||
| """ | ||||||
| units_obj = ax_map.get("units") | ||||||
| if units_obj is None: | ||||||
| return None | ||||||
|
|
@@ -91,6 +130,23 @@ def _normalize_axis_coords( | |||||
| idx: int, | ||||||
| ax_type: str, | ||||||
| ) -> tuple[list[Any], int]: | ||||||
| """Validate explicit ``coords`` for one axis. | ||||||
|
|
||||||
| Categorical and ordinal axes must have non-empty unique string coords; | ||||||
| continuous axes coerce values to numbers and require monotonic | ||||||
| non-decreasing order. | ||||||
|
|
||||||
| Args: | ||||||
| coords_obj: Raw value of ``coords``. | ||||||
| idx: Position in the surrounding ``axes`` list (for diagnostics). | ||||||
| ax_type: Already-validated axis type. | ||||||
|
|
||||||
| Returns: | ||||||
| ``(coords, size)`` pair. | ||||||
|
|
||||||
| Raises: | ||||||
| InvalidRhsSpecError: If validation fails. | ||||||
| """ | ||||||
| if not isinstance(coords_obj, (list, tuple)) or not coords_obj: | ||||||
| raise InvalidRhsSpecError(detail=f"axes[{idx}].coords must be a non-empty list") | ||||||
| coords = list(coords_obj) | ||||||
|
|
@@ -164,6 +220,20 @@ def _compute_axis_deltas(coords: list[float], *, idx: int) -> list[float]: | |||||
| def _generate_continuous_coords( | ||||||
| *, domain: object, size_obj: object, spacing: str, idx: int | ||||||
| ) -> tuple[list[float], int]: | ||||||
| """Generate ``coords`` for a continuous axis from ``domain``/``size``/``spacing``. | ||||||
|
|
||||||
| Args: | ||||||
| domain: Raw ``domain`` mapping with ``lb``/``ub``. | ||||||
| size_obj: Raw ``size`` value (must be an integer >= 2). | ||||||
| spacing: One of ``"linear"``, ``"log"``, ``"geom"``. | ||||||
| idx: Position in the surrounding ``axes`` list (for diagnostics). | ||||||
|
|
||||||
| Returns: | ||||||
| ``(coords, size)`` pair where ``coords`` has length ``size``. | ||||||
|
|
||||||
| Raises: | ||||||
| InvalidRhsSpecError: On invalid bounds, size, or spacing. | ||||||
| """ | ||||||
| domain_map = ( | ||||||
| _ensure_mapping(domain, name=f"axes[{idx}].domain") | ||||||
| if domain is not None | ||||||
|
|
@@ -221,6 +291,21 @@ def _generate_continuous_coords( | |||||
| def _normalize_single_axis( | ||||||
| ax_map: Mapping[str, Any], *, idx: int, seen: set[str] | ||||||
| ) -> dict[str, Any]: | ||||||
| """Normalize one axis mapping into the canonical record. | ||||||
|
|
||||||
| Args: | ||||||
| ax_map: Raw axis mapping. | ||||||
| idx: Position in the surrounding ``axes`` list (for diagnostics). | ||||||
| seen: Mutable set of already-registered axis names; updated in place. | ||||||
|
|
||||||
| Returns: | ||||||
| Canonical axis dict (``name``, ``type``, ``coords``, ``size``, | ||||||
| and optionally ``deltas``, ``domain``, ``spacing``, ``units``). | ||||||
|
|
||||||
| Raises: | ||||||
| InvalidRhsSpecError: If the axis is categorical or ordinal but | ||||||
| has no ``coords`` field. | ||||||
| """ | ||||||
| name = _normalize_axis_name(ax_map, idx=idx, seen=seen) | ||||||
| ax_type = _normalize_axis_type(ax_map, idx=idx) | ||||||
| spacing = str(ax_map.get("spacing", "linear")).strip().lower() | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice, the doctest provides a clear example that is great for users/developers to quickly get an idea of what the function does either before/after reading the docstring itself.