numpy / numpy/numpy

BUG: `np.ma.innerproduct` throws error with object arrays

Open
#31,736 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

00 - Bug component: numpy.ma
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

Describe the issue:

On the behavior observed in the examples below, np.ma.innerproduct appears to mishandle object-dtype arrays. For the same inputs, np.inner returns the a scalar result, while np.ma.innerproduct raises an internal AttributeError.

Similar to #31019, I report it separately from #31735 because it affects a different API and fails with an exception.

Reproduce the code example:
import numpy as np
a = np.array([1,2,3], dtype=object)
b = np.array([0,1,0], dtype=object)

np.inner(a, b)           # -> 2
np.ma.innerproduct(a, b) # -> AttributeError
Error message:
AttributeError: 'int' object has no attribute 'view'
Python and NumPy Versions:

2.6.0.dev0+git20260623.4357ad1
3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0]

Runtime Environment:

No response

How does this issue affect you or how did you find it:

This issue was identified by an automated testing tool currently being developed by our research team.
Before reporting it, we reviewed the code, documentation and checked the latest development version of Numpy to confirm this observation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported object-array example and compare np.inner with np.ma.innerproduct. Trace the masked-array implementation behind np.ma.innerproduct to find where the scalar is treated as requiring .view; done means the example returns the expected scalar without AttributeError and the behavior has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.