8000 [WIP] add matrix checking function for quiver input by JunTan · Pull Request #7461 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[WIP] add matrix checking function for quiver input #7461

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add matrix checking function for quiv 8000 er input
  • Loading branch information
JunTan committed Nov 15, 2016
commit d8841a86957949b5414c7288861bf83f49cf6979
15 changes: 14 additions & 1 deletion lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ def mkdirs(newdir, mode=0o777):
if exception.errno != errno.EEXIST:
raise


class GetRealpathAndStat(object):
def __init__(self):
self._cache = {}
Expand Down Expand Up @@ -1734,7 +1735,7 @@ def recursive_remove(path):
os.removedirs(fname)
else:
os.remove(fname)
#os.removedirs(path)
# os.removedirs(path)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you really want to touch this function, I'd just alias recursive_remove to shutil.rmtree (with onerror set to remove files) :-) Otherwise this is kind of pointless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just changed the comment part according to the pep8 style. Nothing is changed within the function.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I don't think that's really in the scope of this PR.

else:
os.remove(path)

Expand Down Expand Up @@ -2701,3 +2702,15 @@ def __exit__(self, exc_type, exc_value, traceback):
os.rmdir(path)
except OSError:
pass


def is_matrix(obj):
Copy link
Member

Choose a reason for hiding this comment

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

In my point of view any is_* function must return a boolean value.

Copy link
Member

Choose a reason for hiding this comment

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

I'd indeed rename this check_array

'''
This is a test for whether the input is a matrix.
Copy link
Member

Choose a reason for hiding this comment

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

Can you please use triple double quotes """: this is the convention for docstring, not triple single quotes.

The docstring is also very unclear on what this function does.

If the input is a matrix, raise an error. Otherwise,
return the object as it is.
'''
cast_result = np.asanyarray(obj)
if type(cast_result) == np.matrix:
raise ValueError("The input cannot be matrix")
return obj
Copy link
Member

Choose a reason for hiding this comment

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

You'd want to return the cast objects. Ie, if X is a list, you want the returned object to be an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then should I raise the error in this function or just return false and raise the error inside the function who calls check_array?

10 changes: 10 additions & 0 deletions lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ def __init__(self, ax, *args, **kw):
"""
self.ax = ax
X, Y, U, V, C = _parse_args(*args)
if X:
cbook.is_matrix(X)
if Y:
cbook.is_matrix(Y)
if U:
cbook.is_matrix(U)
if V:
cbook.is_matrix(V)
if C:
cbook.is_matrix(C)
self.X = X
self.Y = Y
self.XY = np.hstack((X[:, np.newaxis], Y[:, np.newaxis]))
Expand Down
0