Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ce49158
Implement histogram binning and bar trace types
tpvasconcelos Nov 30, 2024
334832f
Add histogram example to getting started docs
tpvasconcelos Nov 30, 2024
92ecc23
Move trace objects to traces module and rename `y_shifted` to `y_base`
tpvasconcelos Nov 30, 2024
e4262f5
Rename `validate_coerce_colorscale`
tpvasconcelos Nov 30, 2024
36122c6
Improve test coverage
tpvasconcelos Dec 1, 2024
a4c4628
Improve type annotations
tpvasconcelos Dec 1, 2024
e701e13
Improve type checks and switch from mypy to pyright
tpvasconcelos Dec 2, 2024
ea7eb65
Set `typeCheckingMode` to `standard`
tpvasconcelos Dec 2, 2024
e7b39e5
Migrate from black to the ruff formatter and enable stricter pyright …
tpvasconcelos Dec 2, 2024
bbeae53
Update changelog.md and remove references of the black formatter
tpvasconcelos Dec 2, 2024
6121c56
Merge branch 'main' into 194-histograms
tpvasconcelos Dec 2, 2024
c4798b0
Remove deprecated ruff rules
tpvasconcelos Dec 4, 2024
84c951a
Add tests for `bin_trace_samples` and `bin_samples`
tpvasconcelos Dec 4, 2024
b4579a0
Update default behaviour for `trace_type`
tpvasconcelos Dec 4, 2024
1a0e3ca
Add tests for `nbins`, `get_trace_cls`, and `BarTrace`
tpvasconcelos Dec 4, 2024
5f6ca76
Update basic hist docs
tpvasconcelos Dec 4, 2024
06c4b52
Update getting started docs
tpvasconcelos Dec 4, 2024
6fa1357
Update API docs
tpvasconcelos Dec 5, 2024
3457e52
Add `versionadded` directives
tpvasconcelos Dec 5, 2024
10ca2e1
Remove references to deprecated color utilities
tpvasconcelos Dec 5, 2024
66d25e0
Update changelog.md
tpvasconcelos Dec 5, 2024
3e46c04
Document bar trace nuances
tpvasconcelos Dec 5, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
# env:
# SKIP: "no-commit-to-branch"
# run: tox -e pre-commit-all
- name: Run type checks with mypy
- name: Run type checks
shell: bash
run: tox -e mypy-safe
run: tox -e typing

# Run test suits for all supported platforms and Python versions
software-tests:
Expand Down
12 changes: 1 addition & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,9 @@ repos:
args: [ --no-build-isolation ]
additional_dependencies: [setuptools-scm]

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.19.1
hooks:
- id: blacken-docs

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

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
hooks:
- id: ruff-format
- id: ruff
args: [ --show-fixes, --exit-non-zero-on-fix ]
types_or: [ python, pyi, jupyter ]
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include *.md
include *.toml
include *.yml
include *.yaml
include *.json

# Stubs
recursive-include src py.typed *.pyi
Expand Down
1 change: 1 addition & 0 deletions cicd_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For this reason, the `cicd_utils` directory needs to be made explicitly discover
Static analysis tools will also we need to be made aware of this package:

- For mypy, we can add it to the `files` option in `mypy.ini` to help with import discovery.
- For pyright, we can add it to the `extraPaths` option in `pyrightconfig.json`.
- For ruff's _isort_-implementation, we also added it to the `known-first-party` list (see `ruff.toml`)

### The `cicd/scripts` directory
Expand Down
7 changes: 4 additions & 3 deletions cicd_utils/cicd/compile_plotly_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
used in the docs. It saves the HTML and WebP artefacts to the
`docs/_static/charts` directory.
"""

from __future__ import annotations

from copy import deepcopy
Expand Down Expand Up @@ -116,9 +117,9 @@ def _write_plotlyjs_bundle() -> None:
bundle_path.write_text(plotlyjs, encoding="utf-8")


def compile_plotly_charts() -> None:
# Setup logic ---
# _write_plotlyjs_bundle()
def compile_plotly_charts(update_plotlyjs_bundle: bool = False) -> None:
if update_plotlyjs_bundle:
_write_plotlyjs_bundle()

# Compile all charts ---
if not PATH_STATIC_CHARTS.exists():
Expand Down
1 change: 1 addition & 0 deletions cicd_utils/cicd/scripts/extract_latest_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- The output is written to the `LATEST_RELEASE_NOTES.md` file.
- The body of this file is then used as the body of the GitHub release.
"""

from __future__ import annotations

from pathlib import Path
Expand Down
7 changes: 7 additions & 0 deletions cicd_utils/ridgeplot_examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def load_basic() -> go.Figure:
return main()


def load_basic_hist() -> go.Figure:
from ._basic_hist import main

return main()


def load_lincoln_weather() -> go.Figure:
from ._lincoln_weather import main

Expand All @@ -44,6 +50,7 @@ def load_probly() -> go.Figure:

ALL_EXAMPLES: list[tuple[str, Callable[[], go.Figure]]] = [
("basic", load_basic),
("basic_hist", load_basic_hist),
("lincoln_weather", load_lincoln_weather),
("lincoln_weather_red_blue", load_lincoln_weather_red_blue),
("probly", load_probly),
Expand Down
4 changes: 2 additions & 2 deletions cicd_utils/ridgeplot_examples/_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def main() -> go.Figure:
from ridgeplot import ridgeplot

rng = np.random.default_rng(42)
my_samples = [rng.normal(n / 1.2, size=600) for n in range(7, 0, -1)]
my_samples = [rng.normal(n / 1.2, size=600) for n in range(6, 0, -1)]
fig = ridgeplot(samples=my_samples)
fig.update_layout(height=400, width=800)
fig.update_layout(height=350, width=800)

return fig

Expand Down
24 changes: 24 additions & 0 deletions cicd_utils/ridgeplot_examples/_basic_hist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
import plotly.graph_objects as go


def main() -> go.Figure:
import numpy as np

from ridgeplot import ridgeplot

rng = np.random.default_rng(42)
my_samples = [rng.normal(n / 1.2, size=600) for n in range(7, 0, -1)]
fig = ridgeplot(samples=my_samples, nbins=20)
fig.update_layout(height=350, width=800)

return fig


if __name__ == "__main__":
fig = main()
fig.show()
6 changes: 3 additions & 3 deletions cicd_utils/ridgeplot_examples/_lincoln_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def main(

df = load_lincoln_weather()

months = df.index.month_name().unique() # type: ignore[attr-defined]
months = df.index.month_name().unique() # pyright: ignore[reportAttributeAccessIssue]
samples = [
[
df[df.index.month_name() == month]["Min Temperature [F]"], # type: ignore[attr-defined]
df[df.index.month_name() == month]["Max Temperature [F]"], # type: ignore[attr-defined]
df[df.index.month_name() == month]["Min Temperature [F]"], # pyright: ignore[reportAttributeAccessIssue]
df[df.index.month_name() == month]["Max Temperature [F]"], # pyright: ignore[reportAttributeAccessIssue]
]
for month in months
]
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/charts/basic.html

Large diffs are not rendered by default.

Binary file modified docs/_static/charts/basic.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/charts/basic.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_static/charts/basic_hist.html

Large diffs are not rendered by default.

Binary file added docs/_static/charts/basic_hist.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/charts/basic_hist.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/_static/charts/lincoln_weather.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/_static/charts/lincoln_weather_red_blue.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/_static/charts/probly.html

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ API Reference
ridgeplot.ridgeplot


Color utilities
===============

.. autosummary::
:toctree: public/
:nosignatures:

ridgeplot.list_all_colorscale_names


Data loading utilities
======================

Expand Down
10 changes: 10 additions & 0 deletions docs/api/internal/_obj/traces.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ridgeplot._obj.traces
================

Object-oriented trace interfaces.

.. toctree::
:maxdepth: 1
:glob:

traces/*
7 changes: 7 additions & 0 deletions docs/api/internal/_obj/traces/area.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ridgeplot._obj.traces.area
===========================

Area trace object.

.. automodule:: ridgeplot._obj.traces.area
:private-members:
7 changes: 7 additions & 0 deletions docs/api/internal/_obj/traces/bar.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ridgeplot._obj.traces.bar
===========================

Bar trace object.

.. automodule:: ridgeplot._obj.traces.bar
:private-members:
7 changes: 7 additions & 0 deletions docs/api/internal/_obj/traces/base.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ridgeplot._obj.traces.base
===========================

Base trace object and utilities.

.. automodule:: ridgeplot._obj.traces.base
:private-members:
7 changes: 7 additions & 0 deletions docs/api/internal/hist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ridgeplot._hist
==============

Histogram utilities.

.. automodule:: ridgeplot._hist
:private-members:
10 changes: 10 additions & 0 deletions docs/api/internal/obj.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ridgeplot._obj
================

Object-oriented interfaces.

.. toctree::
:maxdepth: 1
:glob:

_obj/*
39 changes: 25 additions & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import sys
from contextlib import contextmanager
from datetime import datetime
from importlib import import_module
from pathlib import Path
from typing import TYPE_CHECKING

try:
import importlib.metadata as importlib_metadata
except ImportError:
import importlib_metadata # type: ignore[no-redef]
import importlib_metadata # pyright: ignore[no-redef]

try:
from cicd.compile_plotly_charts import compile_plotly_charts
Expand Down Expand Up @@ -204,9 +205,9 @@
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"packaging": ("https://packaging.pypa.io/en/latest", None),
"numpy": ("https://docs.scipy.org/doc/numpy/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"statsmodels": ("https://www.statsmodels.org/stable/", None),
"plotly": ("https://plotly.com/python-api-reference/", None),
}
Expand Down Expand Up @@ -263,18 +264,9 @@
# ------- ._color.interpolation ----------------
"ridgeplot._color.interpolation.ColorscaleInterpolants",
"ridgeplot._color.interpolation.SolidColormode",
# ------- ._figure_factory ---------------------
"ridgeplot._figure_factory.TraceType",
"ridgeplot._figure_factory.TraceTypesArray",
"ridgeplot._figure_factory.ShallowTraceTypesArray",
"ridgeplot._figure_factory.LabelsArray",
"ridgeplot._figure_factory.ShallowLabelsArray",
# ------- ._kde --------------------------------
"ridgeplot._kde.KDEPoints",
"ridgeplot._kde.KDEBandwidth",
"ridgeplot._kde.SampleWeights",
"ridgeplot._kde.SampleWeightsArray",
"ridgeplot._kde.ShallowSampleWeightsArray",
# ------- ._missing ----------------------------
"ridgeplot._missing.MISSING",
"ridgeplot._missing.MissingType",
Expand All @@ -298,13 +290,32 @@
"ridgeplot._types.SamplesRow",
"ridgeplot._types.Samples",
"ridgeplot._types.ShallowSamples",
"ridgeplot._types.TraceType",
"ridgeplot._types.TraceTypesArray",
"ridgeplot._types.ShallowTraceTypesArray",
"ridgeplot._types.LabelsArray",
"ridgeplot._types.ShallowLabelsArray",
"ridgeplot._types.SampleWeights",
"ridgeplot._types.SampleWeightsArray",
"ridgeplot._types.ShallowSampleWeightsArray",
}
for fq in _TYPE_ALIASES_FULLY_QUALIFIED:
module_name, _, type_name = fq.rpartition(".")
try:
import_module(module_name)
except ImportError as e:
raise AssertionError(f"Type alias {fq!r} is not importable: {e}") from e

_TYPE_ALIASES = {fq.split(".")[-1]: fq for fq in _TYPE_ALIASES_FULLY_QUALIFIED}
autodoc_type_aliases = {
**{a: a for a in _TYPE_ALIASES.values()},
**{fq: fq for fq in _TYPE_ALIASES.values()},
}
napoleon_type_aliases = {a: f":data:`~{fq}`" for a, fq in _TYPE_ALIASES.items()}
EXTRA_NAPOLEON_ALIASES = {
"Collection[Color]": r":data:`~collections.abc.Collection`\[:data:`~ridgeplot._types.Color`\]",
}
napoleon_type_aliases.update(EXTRA_NAPOLEON_ALIASES)


# -- sphinx_remove_toctrees ------------------------------------------------------------------------
Expand Down Expand Up @@ -380,5 +391,5 @@ def setup(app: Sphinx) -> None:
compile_plotly_charts()
# app.connect("html-page-context", register_jinja_functions)

app.connect("build-finished", lambda *_: _fix_generated_public_api_rst())
app.connect("build-finished", lambda *_: _fix_html_charts())
app.connect("build-finished", lambda *_: _fix_generated_public_api_rst()) # pyright: ignore[reportUnknownLambdaType]
app.connect("build-finished", lambda *_: _fix_html_charts()) # pyright: ignore[reportUnknownLambdaType]
Loading
Loading