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

Numpy reshape shape to use * #1999

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

clavedeluna
Copy link
Contributor

@clavedeluna clavedeluna commented Jan 31, 2023

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes pylint-dev/pylint#7883

Pylint issue demonstrates a FP. I think this is the right solution, I also tested with this code and made sure pylint no longer showed the messages.

import numpy as np
x = np.zeros(12)
x.reshape(3, 2, 2)
x.reshape((3, 2))
x.reshape(3, 2, 2, order='F')
x.reshape(3, 2, 2, order='F')
x.reshape((3, 2, 2), order='F')

a = np.arange(6).reshape((3, 2))

x.reshape(a, order='F')

np.reshape(a, (2, 3))

np.reshape(a, 6, order='F')

@clavedeluna
Copy link
Contributor Author

I'm not really sure a unit test is needed here but if it does please let me know and hit to where it should be.

@codecov
Copy link

codecov bot commented Jan 31, 2023

Codecov Report

Merging #1999 (734e90b) into main (943cd49) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1999   +/-   ##
=======================================
  Coverage   92.77%   92.77%           
=======================================
  Files          94       94           
  Lines       10931    10931           
=======================================
  Hits        10141    10141           
  Misses        790      790           
Flag Coverage Ξ”
linux 92.53% <ΓΈ> (ΓΈ)
pypy 88.50% <ΓΈ> (ΓΈ)
windows 92.37% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
astroid/brain/brain_numpy_ndarray.py 100.00% <ΓΈ> (ΓΈ)

@clavedeluna clavedeluna added the pylint-tested PRs that don't cause major regressions with pylint label Jan 31, 2023
@@ -120,7 +120,7 @@ def ptp(self, axis=None, out=None): return np.ndarray([0, 0])
def put(self, indices, values, mode='raise'): return None
def ravel(self, order='C'): return np.ndarray([0, 0])
def repeat(self, repeats, axis=None): return np.ndarray([0, 0])
def reshape(self, shape, order='C'): return np.ndarray([0, 0])
def reshape(self, *shape, order='C'): return np.ndarray([0, 0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/numpy/numpy/blob/9d7dca4596d7aeb8f31a261592a33d3b38b93b5f/numpy/__init__.pyi#L1767-L1774

The actual code is a bit different.. I'm not sure how to express this as it feels like we might run into issues with the other form as well..

@cdce8p cdce8p removed their request for review March 9, 2023 11:23
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We install numpy during tests now, so it's possible to add automated tests for this (the example in the description at least).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pylint-tested PRs that don't cause major regressions with pylint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive when using ndarray.reshape with separate arguments for each element of the shape
3 participants