desihub / desitarget

DESI Targeting
BSD 3-Clause "New" or "Revised" License
18 stars 23 forks source link

deprecated np.int and np.float #790

Closed sbailey closed 1 year ago

sbailey commented 2 years ago

Update desitarget code to avoid deprecated usage of np.int and np.float, e.g.

py/desitarget/cuts.py:  if isinstance(Grr, np.float):

cases the following DeprecationWarning in tests:

/global/common/software/desi/cori/desiconda/20211217-2.0.0/code/desitarget/master/py/desitarget/cuts.py:2204: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if isinstance(Grr, np.float):

np.float64, np.int32, np.int32, etc are fine, and I think this is too:

py/desitarget/mock/build.py:    nchunk = 4**np.int(np.log2(nside_chunk) - np.log2(nside))

because that vector-based cast wouldn't work with a naive np.int -> int replacement.

Most other codes have tripped on this via code like np.ones(n, dtype=int); from a quick grep most desitarget cases are a little different, e.g. I'm not sure whether isinstance(Grr, float) actually would work for all flavors of numpy floats (the deprecating warning says it would, but please check...).

i.e. check this on a case by case basis and not a naive search/replace.

geordie666 commented 1 year ago

Addressed in #797.