diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2021-08-16 15:22:09 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-16 15:22:09 -0600 |
| commit | db1a3432cb347808f297af51ca16a016fef934b3 (patch) | |
| tree | a26440923a6db95eaa343ae8826ae177f233ed76 /numpy/lib | |
| parent | cde69925a74cafa5c7d3dc3c820f75835c514fb2 (diff) | |
| parent | ed7f30db21f4510e3e6106a68991e8ee21d781ff (diff) | |
| download | numpy-db1a3432cb347808f297af51ca16a016fef934b3.tar.gz | |
Merge pull request #19627 from ankitdwivedi23/ankitd/vectorize-ignore-whitespace
BUG: Ignore whitespaces while parsing gufunc signatures
Diffstat (limited to 'numpy/lib')
| -rw-r--r-- | numpy/lib/function_base.py | 2 | ||||
| -rw-r--r-- | numpy/lib/tests/test_function_base.py | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index b43a1d666..6f19619bb 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1866,6 +1866,8 @@ def _parse_gufunc_signature(signature): Tuple of input and output core dimensions parsed from the signature, each of the form List[Tuple[str, ...]]. """ + signature = re.sub(r'\s+', '', signature) + if not re.match(_SIGNATURE, signature): raise ValueError( 'not a valid gufunc signature: {}'.format(signature)) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index e1b615223..1d694e92f 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1528,6 +1528,21 @@ class TestVectorize: ([('x',)], [('y',), ()])) assert_equal(nfb._parse_gufunc_signature('(),(a,b,c),(d)->(d,e)'), ([(), ('a', 'b', 'c'), ('d',)], [('d', 'e')])) + + # Tests to check if whitespaces are ignored + assert_equal(nfb._parse_gufunc_signature('(x )->()'), ([('x',)], [()])) + assert_equal(nfb._parse_gufunc_signature('( x , y )->( )'), + ([('x', 'y')], [()])) + assert_equal(nfb._parse_gufunc_signature('(x),( y) ->()'), + ([('x',), ('y',)], [()])) + assert_equal(nfb._parse_gufunc_signature('( x)-> (y ) '), + ([('x',)], [('y',)])) + assert_equal(nfb._parse_gufunc_signature(' (x)->( y),( )'), + ([('x',)], [('y',), ()])) + assert_equal(nfb._parse_gufunc_signature( + '( ), ( a, b,c ) ,( d) -> (d , e)'), + ([(), ('a', 'b', 'c'), ('d',)], [('d', 'e')])) + with assert_raises(ValueError): nfb._parse_gufunc_signature('(x)(y)->()') with assert_raises(ValueError): |
