Repository: ivy-llc/ivy

Issue:
nanmean



Discussion:
Can you assign me to this task?
please,  ignore PR #11818 
please , review PR #11822 
according to directions given in comments of pr #11822  by james ([jkeane508](https://github.com/jkeane508)) , a new PR #11972  is opened
would you please review this PR #11972
thank you
Leon Harraka ([Lexticc](https://github.com/Lexticc))

Resolving patch:
diff --git a/ivy/functional/frontends/jax/numpy/statistical.py b/ivy/functional/frontends/jax/numpy/statistical.py
--- a/ivy/functional/frontends/jax/numpy/statistical.py
+++ b/ivy/functional/frontends/jax/numpy/statistical.py
@@ -431,3 +431,28 @@ def ptp(a, axis=None, out=None, keepdims=False):
     x = ivy.max(a, axis=axis, keepdims=keepdims)
     y = ivy.min(a, axis=axis, keepdims=keepdims)
     return ivy.subtract(x, y)
+
+
+@handle_jax_dtype
+@to_ivy_arrays_and_back
+def nanmean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=None):
+    axis = tuple(axis) if isinstance(axis, list) else axis
+    if dtype is None:
+        dtype = "float64" if ivy.is_int_dtype(a) else a.dtype
+    if ivy.is_array(where):
+        where1 = ivy.array(where, dtype=ivy.bool)
+        a = ivy.where(where1, a, ivy.full_like(a, ivy.nan))
+    nan_mask1 = ivy.isnan(a)
+    not_nan_mask1 = ~ivy.isnan(a)
+    b1 = ivy.where(ivy.logical_not(nan_mask1), a, ivy.zeros_like(a))
+    array_sum1 = ivy.sum(b1, axis=axis, dtype=dtype, keepdims=keepdims, out=out)
+    not_nan_mask_count1 = ivy.sum(
+        not_nan_mask1, axis=axis, dtype=dtype, keepdims=keepdims, out=out
+    )
+    count_zero_handel = ivy.where(
+        not_nan_mask_count1 != 0,
+        not_nan_mask_count1,
+        ivy.full_like(not_nan_mask_count1, ivy.nan),
+    )
+    ret_nanmean = ivy.divide(array_sum1, count_zero_handel)
+    return ret_nanmean


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_statistical.py b/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_statistical.py
--- a/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_statistical.py
+++ b/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_statistical.py
@@ -912,3 +912,63 @@ def test_jax_numpy_ptp(
         out=None,
         keepdims=keep_dims,
     )
+
+
+# nanmean
+@st.composite
+def _get_castable_dtype_with_nan(draw):
+    available_dtypes = helpers.get_dtypes("float")
+    shape = draw(helpers.get_shape(min_num_dims=1, max_num_dims=4, max_dim_size=6))
+    dtype, values = draw(
+        helpers.dtype_and_values(
+            available_dtypes=available_dtypes,
+            num_arrays=1,
+            large_abs_safety_factor=6,
+            small_abs_safety_factor=24,
+            safety_factor_scale="log",
+            shape=shape,
+            allow_nan=True,
+            allow_inf=True,
+        )
+    )
+    axis = draw(helpers.get_axis(shape=shape, force_int=True))
+    dtype1, values, dtype2 = draw(
+        helpers.get_castable_dtype(draw(available_dtypes), dtype[0], values[0])
+    )
+    return dtype1, [values], axis, dtype2
+
+
+@handle_frontend_test(
+    fn_tree="jax.numpy.nanmean",
+    dtype_x_axis_castable_dtype=_get_castable_dtype_with_nan(),
+    keepdims=st.booleans(),
+    where=np_helpers.where(),
+)
+def test_jax_numpy_nanmean(
+    dtype_x_axis_castable_dtype,
+    frontend,
+    test_flags,
+    fn_tree,
+    on_device,
+    where,
+    keepdims,
+):
+    input_dtypes, x, axis, castable_dtype = dtype_x_axis_castable_dtype
+    where, input_dtypes, test_flags = np_helpers.handle_where_and_array_bools(
+        where=where,
+        input_dtype=[input_dtypes],
+        test_flags=test_flags,
+    )
+    np_helpers.test_frontend_function(
+        input_dtypes=input_dtypes,
+        frontend=frontend,
+        test_flags=test_flags,
+        on_device=on_device,
+        fn_tree=fn_tree,
+        a=x[0],
+        axis=axis,
+        dtype=castable_dtype,
+        out=None,
+        keepdims=keepdims,
+        where=where,
+    )