Skip to content

np.vectorize doesn't ignore white space in signature #19597

Closed

Description

@jrbourbeau

It looks like the signature= keyword argument to np.vectorize doesn't ignore white space characters (see the reproducer below). Based on the description of gufunc signatures, I would have expected white space to also be ignored in the signature= keyword to np.vectorize.

This was originally noticed in dask/dask#7972

Reproducing code example:

import numpy as np
np.vectorize(np.convolve, signature='(n),(m )->(k)')  # NOTE there is a space after `m`

Note that if we remove the space after m, then no error is raised

Error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-0f1af5e625a4> in <module>
----> 1 np.vectorize(np.convolve, signature='(n),(m )->(k)')

~/mambaforge/envs/dask/lib/python3.9/site-packages/numpy/lib/function_base.py in __init__(self, pyfunc, otypes, doc, excluded, cache, signature)
   2129
   2130         if signature is not None:
-> 2131             self._in_and_out_core_dims = _parse_gufunc_signature(signature)
   2132         else:
   2133             self._in_and_out_core_dims = None

~/mambaforge/envs/dask/lib/python3.9/site-packages/numpy/lib/function_base.py in _parse_gufunc_signature(signature)
   1865     """
   1866     if not re.match(_SIGNATURE, signature):
-> 1867         raise ValueError(
   1868             'not a valid gufunc signature: {}'.format(signature))
   1869     return tuple([tuple(re.findall(_DIMENSION_NAME, arg))

ValueError: not a valid gufunc signature: (n),(m )->(k)

NumPy/Python version information:

In [4]: import sys, numpy; print(numpy.__version__, sys.version)
1.21.1 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:36:15)
[Clang 11.1.0 ]

Activity

  1. ankitdwivedi23 commented on Aug 4, 2021

    @ankitdwivedi23
    Contributor

    Hi! Can I work on this issue?

  2. jrbourbeau commented on Aug 4, 2021

    @jrbourbeau
    ContributorAuthor

    Yes, please feel free to! You don't need to ask for permission to work on an issue

  3. ankitdwivedi23 commented on Aug 7, 2021

    @ankitdwivedi23
    Contributor

    I have attempted to fix this issue in this pull request. Would really appreciate any comments or suggestions.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions