Skip to content

pep8ify examples/ part 3 #3183

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 4 commits into from
Closed

Conversation

twmr
Copy link
Contributor

@twmr twmr commented Jul 4, 2014

examples/pylab_examples, examples/units and examples/use_interface remain to be done.

@@ -82,48 +84,53 @@ def get_ind_under_point(self, event):
xy = np.asarray(self.pathpatch.get_path().vertices)
xyt = self.pathpatch.get_transform().transform(xy)
xt, yt = xyt[:, 0], xyt[:, 1]
d = np.sqrt((xt-event.x)**2 + (yt-event.y)**2)
d = np.abs((xt - event.x) + (yt - event.y) * 1j)
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 did this in several places - hope you are fine with that.

I just discovered that the sqrt version is the fastest compared to the complex version and np.hypot.

In [5]: import numpy as np

In [6]: a = np.random.rand(int(1e6))

In [7]: b = np.random.rand(int(1e6))

In [10]: %timeit np.abs(a + 1j * b)
10 loops, best of 3: 40.4 ms per loop

In [11]: %timeit np.hypot(a, b)
10 loops, best of 3: 23.4 ms per loop

In [12]: %timeit np.sqrt(a ** 2 + b ** 2)
100 loops, best of 3: 8.13 ms per loop

Probably I'll change it back, WDYT ?

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 changed it to np.hypot

@ianthomas23
Copy link
Member

I don't approve of the blanket use of whitespace around all binary operators. In many cases this renders the code less readable than before, and is contrary to PEP8, which says:

If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgment; however.

PEP8 encourages

x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)

and discourages

x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)

I'll indicate some of the changes that use excessive whitespace regardless of operator priority, contrary to PEP8.

If we are going to use an automated tool to correct PEP8 compliance, it must be configured to be less aggressive than this.

print('idle', on_idle.count)
line1.set_ydata(np.sin(2*np.pi*t*(N-on_idle.count)/float(N)))
line1.set_ydata(np.sin(2 * np.pi * t * (N - on_idle.count) / float(N)))
Copy link
Member

Choose a reason for hiding this comment

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

Excessive whitespace.

@twmr
Copy link
Contributor Author

twmr commented Jul 4, 2014

@ianthomas23 I absolutely agree (see PyCQA/pycodestyle#292 (comment)).

@twmr
Copy link
Contributor Author

twmr commented Jul 4, 2014

@ianthomas23 I think it would be the best to ignore the space issues for the moment and fix them in a different PR

@tacaswell
Copy link
Member

I want to hold off on these until after 1.4. Touching this many files makes me nervous.

@tacaswell tacaswell added this to the v1.4.x milestone Jul 4, 2014
@twmr
Copy link
Contributor Author

twmr commented Aug 8, 2014

I'll recreate a PR once 1.4 is released.

@twmr twmr closed this Aug 8, 2014
@twmr twmr mentioned this pull request Aug 27, 2014
@twmr twmr deleted the pep8examplesapiv3 branch October 10, 2014 14:24
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.

5 participants