Skip to content

Commit a7a675d

Browse files
authored
deprecate infer_interval_breaks (#32)
* deprecate infer_interval_breaks * update docs
1 parent 22c242c commit a7a675d

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
## v0.3.0 (unreleased)
55

6+
### Deprecations
7+
8+
* Deprecated `mpu.infer_interval_breaks` as this is no longer necessary with matplotlib v3.2
9+
and cartopy v0.21 [#32](https://github.com/mathause/mplotutils/pull/32).
10+
611
### Bug fixes
712

813
* Fixed compatibility of `mpu.colorbar` with `bbox_inches="tight"` for matplotlib 3.4 and

mplotutils/cartopy_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# code by M.Hauser
22

3+
import warnings
4+
35
import cartopy.crs as ccrs
46
import cartopy.util as cutil
57
import matplotlib.pyplot as plt
@@ -40,6 +42,14 @@ def sample_data_map(nlons, nlats):
4042
def infer_interval_breaks(x, y, clip=False):
4143
"""find edges of gridcells, given their centers"""
4244

45+
# TODO: require cartopy >= 0.21 when removing this function
46+
warnings.warn(
47+
"It's no longer necessary to compute the edges of the array. This is now done"
48+
"in matplotlib. This function will be removed from mplotutils in a future "
49+
"version.",
50+
FutureWarning,
51+
)
52+
4353
if len(x.shape) == 1:
4454
x = _infer_interval_breaks(x)
4555
y = _infer_interval_breaks(y)

mplotutils/tests/test_infer_interval_breaks.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import numpy as np
2+
import pytest
23
from numpy.testing import assert_array_equal # noqa: F401
34

45
from mplotutils.cartopy_utils import _infer_interval_breaks, infer_interval_breaks
56

67

8+
def test_infer_interval_breaks_warns():
9+
10+
with pytest.warns(FutureWarning):
11+
infer_interval_breaks(np.array([1, 2, 3]), np.array([1, 2, 3]))
12+
13+
714
def test__infer_interval_breaks():
815
assert_array_equal([-0.5, 0.5, 1.5], _infer_interval_breaks([0, 1]))
916
assert_array_equal(
@@ -26,6 +33,7 @@ def test__infer_interval_breaks():
2633
# _infer_interval_breaks(np.array([0, 2, 1]))
2734

2835

36+
@pytest.mark.filterwarnings("ignore:It's no longer necessary")
2937
def test_infer_interval_breaks():
3038

3139
# 1D
@@ -52,6 +60,7 @@ def test_infer_interval_breaks():
5260
np.testing.assert_allclose(yref, y)
5361

5462

63+
@pytest.mark.filterwarnings("ignore:It's no longer necessary")
5564
def test_infer_interval_breaks_clip():
5665

5766
# no clip
@@ -74,17 +83,3 @@ def test_infer_interval_breaks_clip():
7483

7584
np.testing.assert_allclose(lon_expected, lon_result)
7685
np.testing.assert_allclose(lat_expected, lat_result)
77-
78-
# 2D, as above
79-
80-
# def test_is_monotonic():
81-
82-
# _is_monotonic(coord, axis=0):
83-
"""
84-
>>> _is_monotonic(np.array([0, 1, 2]))
85-
True
86-
>>> _is_monotonic(np.array([2, 1, 0]))
87-
True
88-
>>> _is_monotonic(np.array([0, 2, 1]))
89-
False
90-
"""

0 commit comments

Comments
 (0)