Skip to content

Commit

Permalink
Fix ready-only numpy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Sep 4, 2024
1 parent 6910961 commit 47be047
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changelog
=========

v0.12.2
-------

Bug Fixes
*********

- Fixed :class:`~mizani.bounds.squish` and
:class:`~mizani.bounds.squish_infinite` to work for non writeable pandas
series. This is broken for numpy 2.1.0.


v0.12.1
-------
*2024-08-19*
Expand Down
10 changes: 8 additions & 2 deletions mizani/bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ def squish_infinite(
>>> squish_infinite(arr2, (-10, 9))
array([ 0. , -10. , 0.5 , 0.25, 9. ])
"""
_x = np.array(x, copy=True)
if isinstance(x, pd.Series):
_x = x.to_numpy().copy()
else:
_x = np.array(x, copy=True)
_x[np.isneginf(_x)] = range[0]
_x[np.isposinf(_x)] = range[1]
return _x
Expand Down Expand Up @@ -285,7 +288,10 @@ def squish(
>>> squish([-np.inf, -1.5, 0.2, 0.8, 1.0, np.inf], only_finite=False)
array([0. , 0. , 0.2, 0.8, 1. , 1. ])
"""
_x = np.array(x, copy=True)
if isinstance(x, pd.Series):
_x = x.to_numpy().copy()
else:
_x = np.array(x, copy=True)
finite = np.isfinite(_x) if only_finite else True
_x[np.logical_and(_x < range[0], finite)] = range[0]
_x[np.logical_and(_x > range[1], finite)] = range[1]
Expand Down

0 comments on commit 47be047

Please sign in to comment.