X Tutup
Skip to content

Cleanups#7544

Merged
QuLogic merged 6 commits intomatplotlib:masterfrom
anntzer:cleanup
Dec 4, 2016
Merged

Cleanups#7544
QuLogic merged 6 commits intomatplotlib:masterfrom
anntzer:cleanup

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Dec 1, 2016

What I did during a five-hour flight (split into multiple PRs to keep things reviewable)...

Apparently github doesn't show file renames in the diff, in fact examples/user_interfaces/interactive2.py was renamed as examples/user_interfaces/interactive.py and the previous interactive.py (which was marked as non-working since 2010) was removed.

callable came back as a builtin in Py3.2. NotImplemented is a singleton.

@NelleV NelleV changed the title Cleanups [MRG+1] Cleanups Dec 1, 2016
@NelleV
Copy link
Copy Markdown
Member

NelleV commented Dec 1, 2016

This is going to break so many PRs /o\


def get_colors(c, num):
"""Stretch the color argument to provide the required number num"""
return np.broadcast_to(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Travis is failing because this method isn't available in older numpys.

tools/gh_api.py Outdated
token, = f
return token
except:
except OSError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about IOError?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I missed the fact that the two are not synonyms in Py2 :-) Can open raise both OSError and IOError?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure about open(), but the read token, = f could produce an IOError.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also, thinking about it, what if the file was malformed? (e.g., many lines), in which case a simple readline() might actually be more correct as that would result in an IOError rather than what ever the error is when doing something like a, b = 1, 2, 3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll just make it Exception.

Copy link
Copy Markdown
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Wow, this cleans up so many....interesting things. Especially nice to no longer have 3 separate values defined for pi within the code base.

verbose.report("Could not open font file %s" % fpath)
continue
try:
try:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This probably dates back to before you could actually have an except and finally on the same try.

try:
return super(BackendGtkAgg, self).check()
except:
raise
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think try:...except: raise has to be my favorite of these. WTF?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually the whole method override can go away...

try:
fh = open(fpath, 'rb')
except:
except OSError:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might need IOError here as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

EnvironmentError is what we want, actually.

Copy link
Copy Markdown
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Nothing too major.

if mouseevent.inaxes is None or ax is None or \
mouseevent.inaxes == ax:
if (mouseevent.inaxes is None or ax is None
or mouseevent.inaxes == ax):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Operator goes before the line break.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tend to (very much) favor the newer PEP8 recommendations (https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator) which I think is usually more readable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought it complained on a different PR, but it seems to have passed here? Not too important...

else:
raise ValueError('match must be None, an '
'matplotlib.artist.Artist '
raise ValueError('match must be None, an matplotlib.artist.Artist '
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

an -> a

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

try:
adata = np.array(data)
except:
except Exception:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does it raise other than TypeError and/or ValueError?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

type(data).__array__(data) can raise whatever it wants.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, I thought np.array would wrap that sort of stuff; carry on, then.

if x is not None and y is not None:
inside = ((x >= xmin) and (x <= xmax) and
(y >= ymin) and (y <= ymax))
inside = xmin <= x <= xmax and ymin <= y <= ymax
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know they're all ands, but I'd put parentheses just the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this line reads quite clearly? There's only one and now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know it's redundant, but I like parentheses around the x and y parts; it's not a major thing, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @QuLogic. Extra parentheses can greatly help readability, and in such cases, like this one, they do no harm at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed.

except KeyError:
raise ValueError(
'Supported Postscript/PDF font types are %s' %
list(six.iterkeys(fonttypes)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you make it list(fonttypes.keys())? Why bother with six for this...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just list(fonttypes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even better.

removed.

The ``ArtistInspector.findobj`` method, which was never working due to the lack
of a ``get_children`` method, has been removed.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what was lacking get_children?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The ArtistInspector class.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Dec 2, 2016
@NelleV NelleV changed the title [MRG+1] Cleanups [MRG] Cleanups Dec 2, 2016
@NelleV NelleV changed the title [MRG] Cleanups [MRG+3] Cleanups Dec 2, 2016
@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Dec 3, 2016

Build's failing; looks like old NumPy don't have np.iterable.

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Dec 3, 2016

matplotlib.tests.test_patheffects.test_collection(0, 'collection', *) seems to have genuinely failed on all builds as well.

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Dec 3, 2016

I'm confused: building numpy 1.7.1 from source shows that it does define np.iterable.

Edit: Ah, stupid implicit relative imports

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Dec 3, 2016

The other failure is due to the change from / 180 * 3.141592 to deg2rad in _get_text_path_transform, so the new result image is the correct one...

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Dec 3, 2016

Need to update the other formats, not just the png.

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Dec 3, 2016

Done.

@tacaswell tacaswell closed this Dec 3, 2016
@tacaswell tacaswell reopened this Dec 3, 2016
@tacaswell
Copy link
Copy Markdown
Member

'power cycled' to restart all of the CI

import numpy as np


# Copy-pasted from numpy.lib.stride_tricks 1.11.2.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add this comment on all functions? This will help in the future if any others are added here and these need to be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Dec 3, 2016

Current coverage is 62.02% (diff: 58.33%)

Merging #7544 into master will increase coverage by 0.10%

@@             master      #7544   diff @@
==========================================
  Files           173        174     +1   
  Lines         56177      56296   +119   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          34784      34918   +134   
+ Misses        21393      21378    -15   
  Partials          0          0          

Powered by Codecov. Last update e66d2f1...afa9344

@tacaswell
Copy link
Copy Markdown
Member

restarted the travis test (looks like weird filesystem related failures). The appveyor tests look transient

@QuLogic QuLogic changed the title [MRG+3] Cleanups Cleanups Dec 4, 2016
@QuLogic QuLogic merged commit 5b1d671 into matplotlib:master Dec 4, 2016
@anntzer anntzer deleted the cleanup branch December 4, 2016 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

X Tutup