Skip to content

shims for categorical support for numpy < 1.8 #8591

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

Merged
merged 3 commits into from
May 12, 2017

Conversation

story645
Copy link
Member

@story645 story645 commented May 7, 2017

Matplotlib doesn't render unicode strings with numpy below 1.7 and numpy below 1.8 is buggy with mixed type arrays, truncating strings to the size of the smallest string in the mixed type array. This PR introduces a shim that converts mixed type elements to strings before converting the input into an array, and it has a shim that decodes and encodes unicode, essentially forcing it into utf endpoint ASCII gibberish.

This PR closes #7988

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@anntzer
Copy link
Contributor

anntzer commented May 8, 2017

We already require at least numpy 1.7. It may be better to just jump the minimum version to 1.8. For example, the oldest Ubuntu still not EOL'd is trusty LTS, which has 1.8.1 (https://wiki.ubuntu.com/Releases and http://packages.ubuntu.com/trusty/python/python-numpy).

@story645
Copy link
Member Author

story645 commented May 8, 2017

I'm fine with whichever. This supports down to 1.6 only because I couldn't reproduce the bug on 1.7. (And so don't know if the unicode issues appear with 1.7...)

Also dunno what codecov is mad about

@tacaswell
Copy link
Member

my guess is that by removing the decorator definition + applications you reduced the number of lines (and covered lines) in the tests files (which out changing the number of not-covered lines) so the fraction of covered lines went down slightly.

import collections


def shim_array(data):
Copy link
Member

Choose a reason for hiding this comment

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

might be better to do this as

if LooseVersion(np.__version__) < LooseVersion('1.8.0'):
   def shim_array(data):
        ...
else:
    def shim_array(data):
        return np.array(data, dtype=np.unicode)

so we only do the version check at import time.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Left one comment (to avoid frequently checking the numpy version, but do not think it is worth holding the PR)

@story645
Copy link
Member Author

Updated based @tacaswell's comments. Can this be closed out?

@dstansby dstansby merged commit 52413e0 into matplotlib:master May 12, 2017
@dstansby dstansby added this to the 2.1 (next point release) milestone May 12, 2017
@story645 story645 deleted the cattests branch May 12, 2017 19:13
@story645 story645 restored the cattests branch August 7, 2017 04:04
@story645 story645 deleted the cattests branch October 9, 2017 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

poor categorical support w/ numpy<1.8
4 participants