From d20f82ab42c136dd35c90d0aa80214dd56e4354a Mon Sep 17 00:00:00 2001 From: Keewis Date: Thu, 19 Mar 2020 19:52:58 +0100 Subject: implement quantile / nanquantile --- pint/numpy_func.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pint/numpy_func.py') diff --git a/pint/numpy_func.py b/pint/numpy_func.py index c2ab623..eb77374 100644 --- a/pint/numpy_func.py +++ b/pint/numpy_func.py @@ -726,6 +726,8 @@ for func_str, unit_arguments, wrap_output in [ ("nanmax", "a", True), ("percentile", "a", True), ("nanpercentile", "a", True), + ("quantile", "a", True), + ("nanquantile", "a", True), ("flip", "m", True), ("fix", "x", True), ("trim_zeros", ["filt"], True), -- cgit v1.2.1 From 9aedbd2139d2c8d39810163430e67ba4bff919c4 Mon Sep 17 00:00:00 2001 From: Keewis Date: Thu, 19 Mar 2020 20:12:42 +0100 Subject: don't try to implement a function that does not exist --- pint/numpy_func.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pint/numpy_func.py') diff --git a/pint/numpy_func.py b/pint/numpy_func.py index eb77374..378cad1 100644 --- a/pint/numpy_func.py +++ b/pint/numpy_func.py @@ -260,7 +260,10 @@ def implement_func(func_type, func_str, input_units=None, output_unit=None): # Handle functions in submodules func_str_split = func_str.split(".") - func = getattr(np, func_str_split[0]) + func = getattr(np, func_str_split[0], None) + # If the function is not available, do not attempt to implement it + if func is None: + return for func_str_piece in func_str_split[1:]: func = getattr(func, func_str_piece) -- cgit v1.2.1 From 2f03f3dfe62ba09edbe56034b8e0bc7098623878 Mon Sep 17 00:00:00 2001 From: Keewis Date: Thu, 19 Mar 2020 20:37:18 +0100 Subject: getattr guard the correct function --- pint/numpy_func.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pint/numpy_func.py') diff --git a/pint/numpy_func.py b/pint/numpy_func.py index 378cad1..9061042 100644 --- a/pint/numpy_func.py +++ b/pint/numpy_func.py @@ -675,7 +675,10 @@ def implement_consistent_units_by_argument(func_str, unit_arguments, wrap_output if np is None: return - func = getattr(np, func_str) + func = getattr(np, func_str, None) + # if NumPy does not implement it, do not implement it either + if func is None: + return @implements(func_str, "function") def implementation(*args, **kwargs): -- cgit v1.2.1