Skip to content

np.nan_to_num ValueError: ValueError: Unable to avoid copy #272

Description

@scottyhq

https://tutorial.xarray.dev/fundamentals/03.1_computation_with_xarray.html#applying-arbitrary-functions

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[6], line 1
----> 1 np.nan_to_num(ds.sst, 0)
File ~/miniforge3/envs/xarray-tutorial-v1/lib/python3.12/site-packages/numpy/lib/_type_check_impl.py:460, in nan_to_num(x, copy, nan, posinf, neginf)
366@array_function_dispatch(_nan_to_num_dispatcher)
367defnan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
368"""369 Replace NaN with zero and infinity with large finite numbers (default
370 behaviour) orwith the numbers defined by the user using the `nan`,
(...)
458 array([222222.+111111.j, 111111. +0.j, 111111.+222222.j])
459"""
--> 460 x = _nx.array(x, subok=True, copy=copy)
461 xtype = x.dtype.type
463 isscalar = (x.ndim ==0)
ValueError: Unable to avoid copy while creating an array as requested.
If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)` to allow a copy when needed (no behavior change in NumPy 1.x).
For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.

Seen upgrading package versions (#270) if numpy>=2 in environment

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions