From c7b91282703b8e865eddf8c0aa0f2bdbcd33b2b5 Mon Sep 17 00:00:00 2001 From: ThatDesert <56128805+ThatDesert@users.noreply.github.com> Date: Fri, 15 Aug 2025 18:21:51 +0100 Subject: [PATCH 1/3] Fixes NCAS-CMS/cf-python#890 by trying to conform valid units first. --- cf/data/data.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cf/data/data.py b/cf/data/data.py index cf4b50c167..0cfdf7848e 100644 --- a/cf/data/data.py +++ b/cf/data/data.py @@ -4407,7 +4407,9 @@ def arctan2(cls, x1, x2): x2: array_like X coordinates. *x1* and *x2* must be broadcastable to a common shape (which becomes the shape of the - output). + output). If both *x1* and *x2* have units, they must + be in the same dimension (can be conformed), else + they will be treated as unitless. :Returns: @@ -4434,6 +4436,10 @@ def arctan2(cls, x1, x2): [90.0 -90.0] """ + + if isinstance(getattr(x2, "Units", None), Units): + x1 = conform_units(x1, x2.Units) + try: y = x1.to_dask_array() except AttributeError: From fd3a8a3c927a534087daeec9ff89f2e20a480d0f Mon Sep 17 00:00:00 2001 From: Ollie <56128805+ThatDesert@users.noreply.github.com> Date: Wed, 27 Aug 2025 11:05:37 +0100 Subject: [PATCH 2/3] Improve clarity in function description. Co-authored-by: Sadie L. Bartholomew --- cf/data/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cf/data/data.py b/cf/data/data.py index 0cfdf7848e..d3c6d6371c 100644 --- a/cf/data/data.py +++ b/cf/data/data.py @@ -4408,8 +4408,8 @@ def arctan2(cls, x1, x2): X coordinates. *x1* and *x2* must be broadcastable to a common shape (which becomes the shape of the output). If both *x1* and *x2* have units, they must - be in the same dimension (can be conformed), else - they will be treated as unitless. + be equal or equivalent, in which case they + will be conformed. :Returns: From 05dc56fcb7a14f4a540996c13c66b0ce0a3d3093 Mon Sep 17 00:00:00 2001 From: Ollie <56128805+ThatDesert@users.noreply.github.com> Date: Wed, 27 Aug 2025 11:06:38 +0100 Subject: [PATCH 3/3] Drop type check Co-authored-by: Sadie L. Bartholomew --- cf/data/data.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cf/data/data.py b/cf/data/data.py index d3c6d6371c..abf2d4567b 100644 --- a/cf/data/data.py +++ b/cf/data/data.py @@ -4437,8 +4437,7 @@ def arctan2(cls, x1, x2): """ - if isinstance(getattr(x2, "Units", None), Units): - x1 = conform_units(x1, x2.Units) + x1 = conform_units(x1, x2.Units) try: y = x1.to_dask_array()