Skip to content

Commit

Permalink
Fix DeprecationWarning since NumPy 1.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzie007 committed Apr 19, 2024
1 parent 1b42e5f commit 81fb79d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mpltern/_ternary_parsers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
from collections.abc import Iterable

import numpy as np
import matplotlib as mpl
Expand All @@ -13,6 +14,12 @@ def _get_xy(ax, this, trans):
else:
trans_xy = ax.transData
x, y = ax.transProjection.transform(tlr).T
# If t, l, r are scalar, x, y are also converted to scalar.
# This is to address `DeprecationWarning` raised since NumPy 1.25.0.
# https://github.com/numpy/numpy/pull/10615
if not any(isinstance(_, Iterable) for _ in (t, l, r)):
x = x.item()
y = y.item()
return x, y, trans_xy


Expand Down Expand Up @@ -103,7 +110,7 @@ def parse(ax, *args, **kwargs):
x1, y1, kwargs['transform'] = _get_xy(ax, tlr1, trans)
dx = x1 - x0
dy = y1 - y0
args = (x0.item(), y0.item(), dx.item(), dy.item(), *args)
args = (x0, y0, dx, dy, *args)
return f(ax, *args, **kwargs)

return parse
Expand Down

0 comments on commit 81fb79d

Please sign in to comment.