From a6fa8bd4d9784e84974d38591f9ceb1044cf99d4 Mon Sep 17 00:00:00 2001 From: jucordero Date: Mon, 30 Mar 2026 15:40:51 +0100 Subject: [PATCH 1/2] fixes to numpy deprecated functionality --- agrifoodpy/food/food.py | 7 +++++-- agrifoodpy/food/tests/test_food.py | 14 +++++++++----- agrifoodpy/land/land.py | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/agrifoodpy/food/food.py b/agrifoodpy/food/food.py index ee327f2..ab60f8f 100644 --- a/agrifoodpy/food/food.py +++ b/agrifoodpy/food/food.py @@ -71,13 +71,16 @@ def FoodSupply( "Year": _years} # find positions in output array to organize data - ii = [np.searchsorted(_items, items), np.searchsorted(_years, years)] + ii = [ + np.atleast_1d(np.searchsorted(_items, items)), + np.atleast_1d(np.searchsorted(_years, years)) + ] size = (len(_items), len(_years)) # If regions and are provided, add the coordinate information if regions is not None: _regions = np.unique(regions) - ii.append(np.searchsorted(_regions, regions)) + ii.append(np.atleast_1d(np.searchsorted(_regions, regions))) size = size + (len(_regions),) coords["Region"] = _regions diff --git a/agrifoodpy/food/tests/test_food.py b/agrifoodpy/food/tests/test_food.py index 6210c18..e374f02 100644 --- a/agrifoodpy/food/tests/test_food.py +++ b/agrifoodpy/food/tests/test_food.py @@ -474,11 +474,15 @@ def test_plot_bars(): def test_plot_years(): - da = xr.DataArray(np.arange(15).reshape(5,3), - coords=[('Year', [2010, 2011, 2012, 2013, 2014]), - ('Region', ['A', 'B', 'C'])], - dims=['Year', 'Region']) - + years = [2019, 2010, 2011, 2012, 2013, 2014] + regions = ['A', 'B', 'C'] + + da = xr.DataArray( + np.arange(len(years)*len(regions)).reshape(len(years), len(regions)), + coords=[('Year', years), + ('Region', regions)], + dims=['Year', 'Region']) + fbs = FoodElementSheet(da) # Test default call diff --git a/agrifoodpy/land/land.py b/agrifoodpy/land/land.py index baae270..4fa02d3 100644 --- a/agrifoodpy/land/land.py +++ b/agrifoodpy/land/land.py @@ -277,8 +277,8 @@ def category_match( shape = map_left.shape - left_match = np.in1d(map_left, values_left).reshape(shape) - right_match = np.in1d(map_right, values_right).reshape(shape) + left_match = np.isin(map_left, values_left).reshape(shape) + right_match = np.isin(map_right, values_right).reshape(shape) category_match = map_left.where(left_match).where(right_match) From c306f75e20eb87ddd82e3ae420c93d6772b0f42b Mon Sep 17 00:00:00 2001 From: jucordero Date: Mon, 30 Mar 2026 16:09:48 +0100 Subject: [PATCH 2/2] adjusted tox environments, added latest python version --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index db434a7..7d8390a 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ requires = tox-conda setuptools envlist = - py{39,310}-test{,-latest,-oldest} + py{39,310,311,312,313,314} build_docs [testenv]