Skip to content

ValueError when using numpy>2.0 related to copy=False keyword usage #32

@rbgdet

Description

@rbgdet

see https://numpy.org/doc/2.4/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword

Code:

import pymangle
import numpy as np
LOWZ_S_path = '/Users/raulteixeira/Downloads/mask_DR11v1_LOWZ_South.ply'

lowz_S = pymangle.Mangle(LOWZ_S_path)

good = lowz_S.contains(200, 0)

Error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[3], line 7
      3 LOWZ_S_path = '[/Users/raulteixeira/Downloads/mask_DR11v1_LOWZ_South.ply](http://localhost:8889/mask_DR11v1_LOWZ_South.ply)'
      5 lowz_S = pymangle.Mangle(LOWZ_S_path)
----> 7 good = lowz_S.contains(200, 0)

File [~/miniforge3/envs/mangletest/lib/python3.14/site-packages/pymangle/mangle.py:152](http://localhost:8889/~/miniforge3/envs/mangletest/lib/python3.14/site-packages/pymangle/mangle.py#line=151), in Mangle.contains(self, ra, dec)
    137 """
    138 Check points against mask, returning 1 if contained 0 if not
    139 
   (...)    149 Array of zeros or ones
    150 """
    151 # we specify order to force contiguous
--> 152 ra = array(ra, ndmin=1, dtype=longdouble, copy=False, order='C')
    153 dec = array(dec, ndmin=1, dtype=longdouble, copy=False, order='C')
    154 return super(Mangle, self).contains(ra, dec)

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.

I think the fix is to turn all copy=False keywords into copy=None in https://github.com/esheldon/pymangle/blob/master/pymangle/mangle.py

The .ply file used can be obtained by

wget https://data.sdss.org/sas/dr11/boss/lss/mask_DR11v1_LOWZ_South.ply

I am happy to share details of my environment setup upon request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions