Skip to content

False positive: "Does not support item assignment" error with np.zeros_like #2747

Closed
pylint-dev/astroid
#664
@Max16hr

Description

@Max16hr

Hi there!
Pylint gives a false-positive error while using numpy.zeros_like().
This numpy method will return a ndarray object. But while trying to address this object by indexing, pylint will raise an error although python works fine.

Code to reproduce:.

import numpy as np

a = np.array([[1, 2, 3], [4, 5, 6]])
print(a)
b = np.zeros_like(a)
print(b)

index = (0, 1)

a[index] = 9
print(a)

b[index] = 9
print(b)

Current behavior

Pylint gives

'b' does not support item assignment

in line 13. But Python runs the program without any problem.

Same issue with np.full_like(), np.empty_like(), np.ones_like().

Expected behavior

No pylint error.
Workaround: In line 5, change to b = np.array(np.zeros_like(a)).

pylint --version output

pylint 2.2.2
astroid 2.1.0
Python 3.7.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions