Skip to content

Commit

Permalink
Add missing shape parameter to numpy methods (#1450)
Browse files Browse the repository at this point in the history
Closes pylint-dev/pylint#5871

Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 9, 2022
1 parent 81235ff commit 6d81868
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -27,6 +27,11 @@ Release date: TBA
to unexpected errors. Overwriting them with ``None`` will cause a fallback
to the already supported way of PyPy 3.7.

* Add missing ``shape`` parameter to numpy ``zeros_like``, ``ones_like``,
and ``full_like`` methods.

Closes PyCQA/pylint#5871


What's New in astroid 2.10.1?
=============================
Expand Down
6 changes: 3 additions & 3 deletions astroid/brain/brain_numpy_core_numeric.py
Expand Up @@ -24,9 +24,9 @@ def numpy_core_numeric_transform():
"""
# different functions defined in numeric.py
import numpy
def zeros_like(a, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
def ones_like(a, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
def full_like(a, fill_value, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
def zeros_like(a, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0))
def ones_like(a, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0))
def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0))
"""
)

Expand Down
2 changes: 1 addition & 1 deletion requirements_test_brain.txt
@@ -1,7 +1,7 @@
attrs
types-attrs
nose
numpy
numpy>=1.17.0
python-dateutil
types-python-dateutil
six
Expand Down
25 changes: 25 additions & 0 deletions tests/unittest_brain_numpy_core_numeric.py
Expand Up @@ -7,7 +7,11 @@

# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE

import unittest
from typing import List

import pytest

try:
import numpy # pylint: disable=unused-import
Expand Down Expand Up @@ -62,5 +66,26 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
)


@pytest.mark.skipif(not HAS_NUMPY, reason="This test requires the numpy library.")
@pytest.mark.parametrize(
"method, expected_args",
[
("zeros_like", ["a", "dtype", "order", "subok", "shape"]),
("full_like", ["a", "fill_value", "dtype", "order", "subok", "shape"]),
("ones_like", ["a", "dtype", "order", "subok", "shape"]),
("ones", ["shape", "dtype", "order"]),
],
)
def test_function_parameters(method: str, expected_args: List[str]) -> None:
instance = builder.extract_node(
f"""
import numpy
numpy.{method} #@
"""
)
actual_args = instance.inferred()[0].args.args
assert [arg.name for arg in actual_args] == expected_args


if __name__ == "__main__":
unittest.main()

0 comments on commit 6d81868

Please sign in to comment.