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

Release v1.0.1 #12

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .bumper.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumper]
current_version = "1.0.0"
current_version = "1.0.1"

[[tool.bumper.files]]
file = "./pyproject.toml"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/lint_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Set up (deadsnakes) Python ${{ matrix.python-version }}
uses: deadsnakes/action@v3.1.0
uses: deadsnakes/action@v3.2.0
if: endsWith(matrix.python-version, '-dev')
with:
python-version: ${{ matrix.python-version }}
tk: true

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ repos:
- id: python-check-blanket-type-ignore
- id: python-use-type-annotations
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
rev: v0.8.4
hooks:
- id: ruff
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# Changelog
Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (`<major>`.`<minor>`.`<patch>`)

## [v1.0.1]
### Fixed
* #8 Fix snapping error when plotting timedelta-based axis data


## [v1.0.0]
Initial release - yay!
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# matplotlib-window
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/matplotlib-window/1.0.0?logo=python&logoColor=FFD43B)](https://pypi.org/project/matplotlib-window/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/matplotlib-window/1.0.1?logo=python&logoColor=FFD43B)](https://pypi.org/project/matplotlib-window/)
[![PyPI](https://img.shields.io/pypi/v/matplotlib-window?logo=Python&logoColor=FFD43B)](https://pypi.org/project/matplotlib-window/)
[![PyPI - License](https://img.shields.io/pypi/l/matplotlib-window?color=magenta)](https://github.com/sco1/matplotlib-window/blob/main/LICENSE)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/sco1/matplotlib-window/main.svg)](https://results.pre-commit.ci/latest/github/sco1/matplotlib-window/main)
Expand Down
13 changes: 13 additions & 0 deletions matplotlib_window/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import StrEnum
from functools import partial

import numpy as np
from matplotlib.axes import Axes
from matplotlib.backend_bases import Event, FigureCanvasBase, MouseEvent
from matplotlib.lines import Line2D
Expand Down Expand Up @@ -192,6 +193,18 @@ def limit_drag(plotted_data: npt.ArrayLike, query: float) -> float:
# Data series may not be sorted, so use min/max
# I'm not sure how to properly type annotate this right now
min_val, max_val = plotted_data.min(), plotted_data.max() # type: ignore[union-attr]

# Per #8, numpy's timedeltas don't support gt/lt so we need to extract a different value for our
# comparison if we're using them
# If the reach ends up being wider then it might be better to perform a more generic check but
# for now the explicit conversion should cover the currently encountered use cases
if isinstance(min_val, np.timedelta64): # min_val and max_val should be the same type
# I couldn't figure out how to access the timedelta unit that numpy holds internally, but
# casting to float seems to work well enough to keep it in the same dimension being used for
# the plot
min_val = min_val.astype(float)
max_val = max_val.astype(float)

if query > max_val:
return max_val # type: ignore[no-any-return]
elif query < min_val:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "matplotlib-window"
version = "1.0.0"
version = "1.0.1"
description = "Draggable data windowing for matplotlib plots"
authors = [
{name = "sco1", email = "[email protected]"}
Expand Down
20 changes: 20 additions & 0 deletions tests/test_base_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ def test_limit_drag(query: NUMERIC_T, truth_out: NUMERIC_T) -> None:
assert limit_drag(plotted_data=PLOTTED_DATA, query=query) == pytest.approx(truth_out)


PLOTTED_TIMEDELTA = np.array([np.timedelta64(i) for i in range(1, 6)])
NP_TIMEDELTA_LIMIT_DRAG_TEST_CASES = (
(-1, 1),
(-1.0, 1),
(1, 1),
(1.0, 1.0),
(3, 3),
(3.0, 3),
(5, 5),
(5.0, 5),
(7, 5),
(7.0, 5),
)


@pytest.mark.parametrize(("query", "truth_out"), NP_TIMEDELTA_LIMIT_DRAG_TEST_CASES)
def test_limit_np_timedelta_drag(query: NUMERIC_T, truth_out: NUMERIC_T) -> None:
assert limit_drag(plotted_data=PLOTTED_TIMEDELTA, query=query) == pytest.approx(truth_out)


def test_transform_rect() -> None:
_, ax = plt.subplots()
ax.set(xlim=(-10, 10), ylim=(-10, 10))
Expand Down
564 changes: 288 additions & 276 deletions uv.lock

Large diffs are not rendered by default.

Loading