Skip to content

Commit d18b99a

Browse files
authored
Release v1.0.1
2 parents c22082b + d1ac15a commit d18b99a

File tree

9 files changed

+335
-281
lines changed

9 files changed

+335
-281
lines changed

.bumper.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.bumper]
2-
current_version = "1.0.0"
2+
current_version = "1.0.1"
33

44
[[tool.bumper.files]]
55
file = "./pyproject.toml"

.github/workflows/lint_test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ jobs:
5858
python-version: ${{ matrix.python-version }}
5959

6060
- name: Set up (deadsnakes) Python ${{ matrix.python-version }}
61-
uses: deadsnakes/action@v3.1.0
61+
uses: deadsnakes/action@v3.2.0
6262
if: endsWith(matrix.python-version, '-dev')
6363
with:
6464
python-version: ${{ matrix.python-version }}
65+
tk: true
6566

6667
- name: Install dependencies
6768
run: |

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ repos:
3535
- id: python-check-blanket-type-ignore
3636
- id: python-use-type-annotations
3737
- repo: https://github.com/astral-sh/ruff-pre-commit
38-
rev: v0.8.1
38+
rev: v0.8.4
3939
hooks:
4040
- id: ruff

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# Changelog
22
Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (`<major>`.`<minor>`.`<patch>`)
3+
4+
## [v1.0.1]
5+
### Fixed
6+
* #8 Fix snapping error when plotting timedelta-based axis data
7+
8+
9+
## [v1.0.0]
10+
Initial release - yay!

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# matplotlib-window
2-
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/matplotlib-window/1.0.0?logo=python&logoColor=FFD43B)](https://pypi.org/project/matplotlib-window/)
2+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/matplotlib-window/1.0.1?logo=python&logoColor=FFD43B)](https://pypi.org/project/matplotlib-window/)
33
[![PyPI](https://img.shields.io/pypi/v/matplotlib-window?logo=Python&logoColor=FFD43B)](https://pypi.org/project/matplotlib-window/)
44
[![PyPI - License](https://img.shields.io/pypi/l/matplotlib-window?color=magenta)](https://github.com/sco1/matplotlib-window/blob/main/LICENSE)
55
[![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)

matplotlib_window/base.py

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import StrEnum
44
from functools import partial
55

6+
import numpy as np
67
from matplotlib.axes import Axes
78
from matplotlib.backend_bases import Event, FigureCanvasBase, MouseEvent
89
from matplotlib.lines import Line2D
@@ -192,6 +193,18 @@ def limit_drag(plotted_data: npt.ArrayLike, query: float) -> float:
192193
# Data series may not be sorted, so use min/max
193194
# I'm not sure how to properly type annotate this right now
194195
min_val, max_val = plotted_data.min(), plotted_data.max() # type: ignore[union-attr]
196+
197+
# Per #8, numpy's timedeltas don't support gt/lt so we need to extract a different value for our
198+
# comparison if we're using them
199+
# If the reach ends up being wider then it might be better to perform a more generic check but
200+
# for now the explicit conversion should cover the currently encountered use cases
201+
if isinstance(min_val, np.timedelta64): # min_val and max_val should be the same type
202+
# I couldn't figure out how to access the timedelta unit that numpy holds internally, but
203+
# casting to float seems to work well enough to keep it in the same dimension being used for
204+
# the plot
205+
min_val = min_val.astype(float)
206+
max_val = max_val.astype(float)
207+
195208
if query > max_val:
196209
return max_val # type: ignore[no-any-return]
197210
elif query < min_val:

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "matplotlib-window"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
description = "Draggable data windowing for matplotlib plots"
55
authors = [
66
{name = "sco1", email = "[email protected]"}

tests/test_base_helpers.py

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ def test_limit_drag(query: NUMERIC_T, truth_out: NUMERIC_T) -> None:
2424
assert limit_drag(plotted_data=PLOTTED_DATA, query=query) == pytest.approx(truth_out)
2525

2626

27+
PLOTTED_TIMEDELTA = np.array([np.timedelta64(i) for i in range(1, 6)])
28+
NP_TIMEDELTA_LIMIT_DRAG_TEST_CASES = (
29+
(-1, 1),
30+
(-1.0, 1),
31+
(1, 1),
32+
(1.0, 1.0),
33+
(3, 3),
34+
(3.0, 3),
35+
(5, 5),
36+
(5.0, 5),
37+
(7, 5),
38+
(7.0, 5),
39+
)
40+
41+
42+
@pytest.mark.parametrize(("query", "truth_out"), NP_TIMEDELTA_LIMIT_DRAG_TEST_CASES)
43+
def test_limit_np_timedelta_drag(query: NUMERIC_T, truth_out: NUMERIC_T) -> None:
44+
assert limit_drag(plotted_data=PLOTTED_TIMEDELTA, query=query) == pytest.approx(truth_out)
45+
46+
2747
def test_transform_rect() -> None:
2848
_, ax = plt.subplots()
2949
ax.set(xlim=(-10, 10), ylim=(-10, 10))

uv.lock

+288-276
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)