-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: array_view construction for empty arrays #5106
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
Conversation
Huh... Travis hasn't been invoked... |
Must be the recent AWS outage. Perhaps if I make some small change to the commits? |
Unless ND==0, in which case return success but don't clobber the m_shape and m_strides members.
Seems to be failing in svg tests. I don't have the prerequisites on my system, so the tests were skipped as KNOWNFAIL. |
attn @mdboom |
Tests pass and nothing seems wrong, but I have no experience with these parts of the code. Who other than @mdboom can review this? |
Maybe @ianthomas23? Or @njsmith? |
I've looked at the comment thread and the patch, and I still have no idea
|
I agree that |
I guess I will fall back on my default method of sounding like I know something in a code review. Could you add some tests? |
Instead change callers to have empty arrays of the right shape.
I think we can do without allowing shape mismatches, it just means a few changes to the calling code. We don't have C++ tests yet and I hesitate to add a test framework for a bugfix commit close to a release. |
#5105 has a good test if nothing else |
@@ -2244,6 +2244,21 @@ def _reshape_2D(X): | |||
return X | |||
|
|||
|
|||
def ensure_3d(arr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to make this a public function? We now have _check_1d()
, _reshape_2D
, and this new ensure_3d
(notice the inconsistency with the case of "d/D").
Why don't we make this private, and make a new issue to unify the logic across these three functions later (if possible)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have thought that an underscore in the beginning means a function that is only called from within cbook, but clearly some underscored functions are called from elsewhere. What is the intended meaning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.python.org/dev/peps/pep-0008/#id29
It means that it is to be treated as being for internal use only. This
gives developers the freedom to modify the API of such modules or functions
without warning or deprecation cycles. As noted later in PEP8, it is easier
to start with something as private and then make it public later, as
opposed to releasing it as public and then modifying it later.
On Mon, Sep 28, 2015 at 10:23 AM, Jouni K. Seppänen <
notifications@github.com> wrote:
In lib/matplotlib/cbook.py
#5106 (comment):@@ -2244,6 +2244,21 @@ def _reshape_2D(X):
return X+def ensure_3d(arr):
I would have thought that an underscore in the beginning means a function
that is only called from within cbook, but clearly some underscored
functions are called from elsewhere. What is the intended meaning?—
Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5106/files#r40557282.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 doesn't really say what the boundaries of internal use are, but I guess here it means internal to matplotlib. Ok, I'll change this.
It's not exactly the same, but we really use it just for empty arrays, so it shouldn't actually matter.
On second thoughts, |
If that's the case, then are we also able to do away with the changes in collections.py? |
No. |
ok, makes sense. From the python side of things, this looks good. I can't really speak for the C++ side, but I don't really see anything troubling. |
If @mdboom does not weigh in by this evening I will merge. |
_transforms = [] | ||
|
||
|
||
_transforms = np.empty((0, 3, 3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you've touched it, would you mind adding a #:
style docstring for what _transforms is supposed to be - this will make reviewing (and editing) this part of the code easier in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this #:
style documented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @pelson just means to add a normal comment explaining what the expected shape of _transfroms
is and why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see with git grep
that there is a small number of #:
comments in the code, but that's not a very easy thing to search. Does Sphinx do something special with them, or some other tool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it does: http://sphinx-doc.org/ext/autodoc.html#directive-autoattribute
FIX: array_view construction for empty arrays
Thanks folks. |
Fixes #5105. The logic gets a little bit complicated, since a lot of tests started failing at first. The last commit accepts e.g. an array of shape (0,) when expecting a three-dimensional array, which should be safe since there is no data in the array anyway, and this case does happen in our code.