From fa31bcdac8e777c3c37b461ac3c5406aafe5632f Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Sun, 5 Oct 2025 13:31:18 +0200 Subject: [PATCH 1/3] rm debug prints --- ultraplot/ticker.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ultraplot/ticker.py b/ultraplot/ticker.py index 7e22010d..4dfa7bfc 100644 --- a/ultraplot/ticker.py +++ b/ultraplot/ticker.py @@ -426,24 +426,19 @@ def __call__(self, x, pos=None): x, tail = self._neg_pos_format(x, self._negpos, wraprange=self._wraprange) # Default string formatting - print(x, pos) string = super().__call__(x, pos) - print(string) # Fix issue where non-zero string is formatted as zero string = self._fix_small_number(x, string) - print(string) # Custom string formatting string = self._minus_format(string) - print(string) if self._zerotrim: string = self._trim_trailing_zeros(string, self._get_decimal_point()) # Prefix and suffix string = self._add_prefix_suffix(string, self._prefix, self._suffix) string = string + tail # add negative-positive indicator - print(string) return string def get_offset(self): From c4c1fe1891698195d73e83052f58786f2c2f5594 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Sun, 5 Oct 2025 14:07:51 +0200 Subject: [PATCH 2/3] add unittests for autoformatter --- ultraplot/tests/test_tickers.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ultraplot/tests/test_tickers.py b/ultraplot/tests/test_tickers.py index 61791fa0..d977ce8f 100644 --- a/ultraplot/tests/test_tickers.py +++ b/ultraplot/tests/test_tickers.py @@ -731,6 +731,38 @@ def test_autocftime_locator_safe_helpers(): assert locator_noleap._safe_create_datetime(2001, 2, 29) is None +@pytest.mark.parametrize( + "formatter_args, values, expected, ylim", + [ + ({"negpos": "NP"}, [10, -10, 0], ["10P", "10N", "0"], (-20, 20)), + ({"tickrange": (0, 10)}, [5, 11, -1], ["5", "", ""], (0, 10)), + ({"wraprange": (-180, 180)}, [200, -200], ["−160", "160"], (-200, 200)), + ], +) +def test_auto_formatter_options(formatter_args, values, expected, ylim): + from ultraplot.ticker import AutoFormatter + import matplotlib.pyplot as plt + + fig, ax = plt.subplots() + formatter = AutoFormatter(**formatter_args) + ax.xaxis.set_major_formatter(formatter) + ax.plot(values, [0] * len(values), "o") + ax.set_xticks(values) + if ylim is not None: + ax.set_ylim(*ylim) + fig.canvas.draw() + # Set formatter.locs to a broader array to mimic real tick locations + formatter.locs = values + [v + 1 for v in values] + [v - 1 for v in values] + for val, exp in zip(values, expected): + try: + result = formatter(val) + except IndexError: + result = "" + except Exception as e: + assert False, f"For value {val}: unexpected error {e}" + assert result == exp, f"For value {val}: got {result}, expected {exp}" + + def test_autocftime_locator_safe_daily_locator(): from ultraplot.ticker import AutoCFDatetimeLocator From df5dc23ea9c846fbe144b8df9e4f14f02a7a1866 Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Sun, 5 Oct 2025 14:15:52 +0200 Subject: [PATCH 3/3] Update ultraplot/tests/test_tickers.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- ultraplot/tests/test_tickers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ultraplot/tests/test_tickers.py b/ultraplot/tests/test_tickers.py index d977ce8f..bfb3d6e3 100644 --- a/ultraplot/tests/test_tickers.py +++ b/ultraplot/tests/test_tickers.py @@ -751,8 +751,8 @@ def test_auto_formatter_options(formatter_args, values, expected, ylim): if ylim is not None: ax.set_ylim(*ylim) fig.canvas.draw() - # Set formatter.locs to a broader array to mimic real tick locations - formatter.locs = values + [v + 1 for v in values] + [v - 1 for v in values] + # Use the tick locations set by matplotlib after drawing the canvas + # formatter.locs is now set by matplotlib; do not assign manually for val, exp in zip(values, expected): try: result = formatter(val)