Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deprecate is_string_like, is_sequence_of_strings#8011

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 5 commits intomatplotlib:masterfromanntzer:is_string_like
Apr 17, 2017

Conversation

anntzer
Copy link
Contributor

@anntzeranntzer commentedFeb 3, 2017
edited
Loading

While implementing#7996 (see also#7835), I had missed that numpy'sstr_ (andunicode_ on Py2) derive from the corresponding builtin type(s), soisinstance(x, six.text_type) is just as good. So I just inlined that and restored the old definition ofis_string_like, immediately deprecating it.

Would also (upon removal)close#7725.

@QuLogic
Copy link
Member

Has this been true since NumPy 1.7.1?

@anntzer
Copy link
ContributorAuthor

anntzer commentedFeb 3, 2017
edited
Loading

Yes.

$ conda create -n tmpenv --yes python=3.3 numpy=1.7.1 >/dev/null && source activate tmpenv &&python -c 'from numpy import str_, unicode_; print(str in str_.__mro__, str in unicode_.__mro__)'True True

and likewise on Py2 (but withunicode in unicode_.__mro__)

@QuLogicQuLogic added this to the2.1 (next point release) milestoneFeb 3, 2017
@QuLogic
Copy link
Member

Looks like an example might have broken.

@anntzer
Copy link
ContributorAuthor

Fixed.
Axes3D.scatter now doesn't accept 2D inputs anymore (which were silently flattened before). If we want to document the change it should probably go with#7786.

I had missed that numpy's `str_` (and `unicode_` on Py2) derive from thecorresponding builtin type(s), so `isinstance(x, six.string_types)` isjust as good.
`Axes3D.scatter` no longer flattens a 2D color input.
@anntzer
Copy link
ContributorAuthor

rebased. bumping :-)

means that arrays are now never num-like or string-like regardless of their
dtype.
`cbook.is_numlike` now only checks that its argument is an instance of
``(numbers.Number, np.Number)`` and. In particular, this means that arrays are
Copy link
Member

Choose a reason for hiding this comment

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

and what?

Copy link
ContributorAuthor

@anntzeranntzerApr 15, 2017
edited
Loading

Choose a reason for hiding this comment

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

typo, fixed

c_list = []
for c in colors:
c_list.append([c]*20)
c_list.extend([c] *20)
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually related?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

not really, moved out.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

oh actually i remember now, it is.
this is because 3d scatter no longer implicitly flattens its input (see the last hunk of the diff).

Copy link
Member

Choose a reason for hiding this comment

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

Probably should add that to the API what's new, then.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done. Also documented the similar change in#7786 at the same time.


`cbook.is_string_like` and `cbook.is_sequence_of_strings` have been
deprecated. Use ``isinstance(obj, six.string_types)`` and ``all(isinstance(o,
six.string_types) for o in obj) and not iterable(obj)`` instead.
Copy link
Member

Choose a reason for hiding this comment

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

That doesn't seem right:

In [9]:frommatplotlib.cbookimportiterable,is_sequence_of_stringsIn [10]:obj= ['a','b','c']In [11]:is_sequence_of_strings(obj)Out[11]:TrueIn [12]:importsixIn [13]:all(isinstance(o,six.string_types)foroinobj)andnotiterable(obj)Out[13]:False

(using 2.0.0, though)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

the "not" needs to be removed, fixed

raise ValueError("First argument must be a sequence")
nrecs = len(args[0])
margs = []
seqlist = [False] * len(args)
for i, x in enumerate(args):
if (not is_string_like(x)) and iterable(x) and len(x) == nrecs:
if ((not isinstance(x, six.string_types)) and iterable(x)
Copy link
Member

Choose a reason for hiding this comment

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

Can drop extra parentheses.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fixed

@@ -1219,10 +1221,10 @@ def finddir(o, match, case=False):
is True require an exact case match.
"""
if case:
names = [(name, name) for name in dir(o) ifis_string_like(name)]
names = [(name, name) for name in dir(o) ifisinstance(name, six.string_types)]
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this too long?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fixed

@@ -789,7 +789,7 @@ def __init__(self, colors, name='from_list', N=None):
if N is None:
N = len(self.colors)
else:
if (cbook.is_string_like(self.colors) and
if (isinstance(self.colors, six.string_types) and
cbook.is_hashable(self.colors)):
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, what strings are not hashable?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

probably was the case of masked string arrays. removed the now redundant check.

Copy link
Member

Choose a reason for hiding this comment

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

I think there might be a few more of these that I didn't comment on.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Caught two more, should be all fixed now.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see it...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

There's only one line that changesis_hashable there (this one.)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ah sorry, thought you meant overly long lines. Now I have removed the hashability checks too.

@@ -1289,7 +1289,7 @@ def update_from(self, other):

def _get_rgba_face(self, alt=False):
facecolor = self._get_markerfacecolor(alt=alt)
ifis_string_like(facecolor) and facecolor.lower() == 'none':
ifisinstance(facecolor, six.string_types) and facecolor.lower() == 'none':
Copy link
Member

Choose a reason for hiding this comment

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

Probably too long, also.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fixed

if ((is_string_like(s1) and s1.split()[0] == "offset") or
(is_string_like(s2) and s2.split()[0] == "offset")):
if ((isinstance(s1, six.string_types) and s1.split()[0] == "offset") or
(isinstance(s2, six.string_types) and s2.split()[0] == "offset")):
Copy link
Member

Choose a reason for hiding this comment

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

Looks a bit over as well.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fixed

@QuLogicQuLogic changed the titleDeprecate is_string_like, is_sequence_of_strings[MRG+1] Deprecate is_string_like, is_sequence_of_stringsApr 16, 2017
@@ -40,8 +39,6 @@ class BlockingInput(object):
"""
def __init__(self, fig, eventslist=()):
self.fig = fig
if not is_sequence_of_strings(eventslist):
raise ValueError("Requires a sequence of event name strings")
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Because it's not as if the check was really useful anyways -- one can always pass a sequence of invalid event names and it'll be just as bad as of one passed in a sequence of nonstrings.

@tacaswelltacaswell merged commit734c09f intomatplotlib:masterApr 17, 2017
@anntzeranntzer deleted the is_string_like branchApril 17, 2017 01:52
@QuLogicQuLogic changed the title[MRG+1] Deprecate is_string_like, is_sequence_of_stringsDeprecate is_string_like, is_sequence_of_stringsApr 17, 2017
jarrodmillman added a commit to jarrodmillman/networkx that referenced this pull requestSep 10, 2017
jarrodmillman added a commit to jarrodmillman/networkx that referenced this pull requestSep 10, 2017
jarrodmillman added a commit to networkx/networkx that referenced this pull requestSep 10, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v2.1
Development

Successfully merging this pull request may close these issues.

is_string_like returns True for numpyobject arrays
3 participants
@anntzer@QuLogic@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp