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

Some general cleanups #6573

Merged
merged 3 commits into from Jun 17, 2016
Merged

Some general cleanups #6573

merged 3 commits into from Jun 17, 2016

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 11, 2016

  • Remove some very old compatibility layers (sets module, md5 module, etc.)
  • Use astype(float) instead of astype(np.float) and astype(np.float_)
  • Use isinstance(..., MaskedArray) instead of isMaskedArray / isMA.

Some other cleanup ideas:

  • Get rid of if debug prints (mostly present in backend implementations just to indicate that a method has been called): I think that a tool such as https://pypi.python.org/pypi/hunter is typically more appropriate anyways.
  • Reimplement the verbose class on top of the stdlib logging and read off an environment variable such as MPLVERBOSITY instead of command-line arguments which are likely to be set for other purposes.

- Remove some very old compatibility layers (sets module, md5 module,
etc.)
- Use `astype(float)` instead of `astype(np.float)` and
`astype(np.float_)`
- Use `isinstance(..., MaskedArray)` instead of `isMaskedArray` /
`isMA`.
@efiring
Copy link
Member

efiring commented Jun 11, 2016

On 2016/06/10 8:56 PM, Antony Lee wrote:

Use |isinstance(..., MaskedArray)| instead of |isMaskedArray| / |isMA|.

What is the advantage of this change?


from .path import Path

DEBUG = False
# we need this later, but this is very expensive to set up
MINFLOAT = np.MachAr(float).xmin
Copy link
Member

Choose a reason for hiding this comment

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

Have you benchmarked this change. It was done like this for performance reasons. See
2d0cc7d

Copy link
Member

Choose a reason for hiding this comment

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

Ok read the docs it seems like finfo is a cached version of MachAr so it is probably fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a slower than just reading off a global but still much faster than MachAr and even than allocating a new array of size 1.

Copy link
Member

Choose a reason for hiding this comment

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

I am also mildly concerned about this, but this is almost certainly not the bottle neck any more.

@anntzer
Copy link
Contributor Author

anntzer commented Jun 11, 2016

re: isinstance(..., MaskedArray). I always felt a bit uneasy about isMaskedArray / isMA: when I read a function like this my first instinct is "oh, I guess if there's such a function it must do a bit more than checking the type (does it check exact type equality ignoring subclassing? does it do something with array-likes? etc.)". But in fact it's just implemented (after a page-long docstring...) just as a call to isinstance.
Say Python suddenly decided to add an isfloat() function... I think it would widely be considered as unpythonic. I think the same of isMaskedArray.
On the other hand I hardly feel strongly about this change.

@efiring
Copy link
Member

efiring commented Jun 11, 2016

On 2016/06/11 5:48 AM, Antony Lee wrote:

re: |isinstance(..., MaskedArray)|. I always felt a bit uneasy about
|isMaskedArray| / |isMA|: when I read a function like this my first
instinct is "oh, I guess if there's such a function it must do a bit
more than checking the type (does it check exact type equality ignoring
subclassing? does it do something with array-likes? etc.)". But in fact
it's just implemented (after a page-long docstring...) just as a call to
|isinstance|.
Say Python suddenly decided to add an |isfloat()| function... I think it
would widely be considered as unpythonic. I think the same of
|isMaskedArray|.
On the other hand I hardly feel strongly about this change.

I have no objection to making the change; your rationale is fine.

@@ -2344,7 +2343,7 @@ def pts_to_poststep(x, *args):
# do normalization
vertices = _step_validation(x, *args)
# create the output array
steps = ma.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
Copy link
Member

Choose a reason for hiding this comment

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

These got missed in the np.float -> float conversion.

Copy link
Member

Choose a reason for hiding this comment

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

It's also not the masked array zeros, if that makes a difference.

Copy link
Contributor Author

@anntzer anntzer Jun 13, 2016

Choose a reason for hiding this comment

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

There's quite a few np.float left; this one is safe to replace but I'd need to do some more research to figure out how this changes calls to np.issubdtype and others.
WRT to np.zeros vs ma.zeros, see below.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jun 12, 2016
@tacaswell
Copy link
Member

Moving to use logging is yet another of the big projects that I think everyone agrees should be done, but no one has yet found the time to do.

@@ -126,6 +126,7 @@
cycler)

import numpy
import numpy.ma
Copy link
Member

Choose a reason for hiding this comment

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

What effect does this have?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ensure that everyone can directly use np.ma.<xyz> without importing numpy.ma.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, it doesn't do anything at all. It's superfluous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, removed.

@tacaswell
Copy link
Member

👍 if @efiring is happy with the way the MA stuff ended up.

@efiring efiring merged commit 7ae1b06 into matplotlib:master Jun 17, 2016
@anntzer anntzer deleted the cleanups branch June 28, 2016 18:55
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.

None yet

6 participants