8000 BUG: np.size is no longer an instance of FunctionType (nightly/dev build) · Issue #23307 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
BUG: np.size is no longer an instance of FunctionType (nightly/dev build) #23307
Closed
@djhoese

Description

@djhoese

Describe the issue:

I have a package that has a CI environment that installs numpy and many other packages from their current unstable/dev versions (nightly builds) and runs the tests. A couple months ago (I think) we started running into a failure where one of our dependencies (holoviews) started crashing when performing the check isinstance(np.size, types.FunctionType). We are not installing a dev version of holoviews. It seems to be tied to numpy's dev version.

Reproduce the code example:

import numpy as np
import types
assert isinstance(np.size, types.FunctionType)

Error message:

N/A

Runtime information:

[{'numpy_version': '1.25.0.dev0+831.g3b5eff00e',
  'python': '3.9.13 | packaged by conda-forge | (main, May 27 2022, '
            '16:56:21) \n'
            '[GCC 10.3.0]',
  'uname': uname_result(system='Linux', node='janet', release='6.0.12-76060006-generic', version='#202212290932~1674139725~22.04~ca93ccf SMP PREEMPT_DYNAMIC Thu J', machine='x86_64')},
 {'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
                      'found': ['SSSE3',
                                'SSE41',
                                'POPCNT',
                                'SSE42',
                                'AVX',
                                'F16C',
                                'FMA3',
                                'AVX2'],
                      'not_found': ['AVX512F',
                                    'AVX512CD',
                                    'AVX512_KNL',
                                    'AVX512_KNM',
                                    'AVX512_SKX',
                                    'AVX512_CLX',
                                    'AVX512_CNL',
                                    'AVX512_ICL']}},
 {'architecture': 'Haswell',
  'filepath': '/home/davidh/miniconda3/envs/satpy_py39_unstable2/lib/python3.9/site-packages/numpy.libs/libopenblas64_p-r0-15028c96.3.21.so',
  'internal_api': 'openblas',
  'num_threads': 12,
  'prefix': 'libopenblas',
  'threading_layer': 'pthreads',
  'user_api': 'blas',
  'version': '0.3.21'}]

Context for the issue:

I'm not sure how many packages have code like this, but holoviews has this bit of code:

https://github.com/holoviz/holoviews/blob/4e83af3e6af0e19fa6c7e226791011372916fc70/holoviews/plotting/bokeh/hex_tiles.py#L26-L30

    aggregator = param.ClassSelector(
        default=np.size, class_=(types.FunctionType, tuple), doc="""
      Aggregation function or dimension transform used to compute bin
      values. Defaults to np.size to count the number of values
      in each bin.""")

And the param library does this check between that class_ tuple and the default object (in this case np.size):

https://github.com/holoviz/param/blob/cd1b4ae50c01c14c0eb22721e41a9c8fb1e8f738/param/__init__.py#L1381-L1385

        if is_instance:
            if not (isinstance(val, class_)):
                raise ValueError(
                    "%s parameter %r value must be an instance of %s, not %r." %
                    (param_cls, self.name, class_name, val))

I am not a holoviews developer, just use it for one small portion of my package (Satpy). As far as I can tell np.size is defined as a function here:

@array_function_dispatch(_size_dispatcher)
def size(a, axis=None):

So I'm lost as to where/how this is not being satisfied. I've seen the failure on Python 3.9 environments. I have not tried other versions of Python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0