Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing shape parameter to numpy methods #1450

Merged
merged 9 commits into from
Mar 9, 2022
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
mbyrnepr2 marked this conversation as resolved.
Show resolved Hide resolved

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()