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

Simplify implementation of is_numlike & is_string_like.#7996

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
NelleV merged 1 commit intomatplotlib:masterfromanntzer:is_numlike_stringlike
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
`cbook.is_numlike` and `cbook.is_string_like` only perform an instance check
````````````````````````````````````````````````````````````````````````````

`cbook.is_numlike` and `cbook.is_string_like` now only check that
their argument is an instance of ``(numbers.Number, np.Number)`` and
``(six.string_types, np.str_, np.unicode_)`` respectively. In particular, this
means that arrays are now never num-like or string-like regardless of their
dtype.
23 changes: 4 additions & 19 deletionslib/matplotlib/cbook/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@
import gzip
import io
import locale
import numbers
import os
import re
import sys
Expand DownExpand Up@@ -495,19 +496,8 @@ def iterable(obj):

def is_string_like(obj):
"""Return True if *obj* looks like a string"""
if isinstance(obj, six.string_types):
return True
# numpy strings are subclass of str, ma strings are not
if isinstance(obj, np.ma.MaskedArray):
if obj.ndim == 0 and obj.dtype.kind in 'SU':
return True
else:
return False
try:
obj + ''
except:
return False
return True
# (np.str_ == np.unicode_ on Py3).
return isinstance(obj, (six.string_types, np.str_, np.unicode_))


def is_sequence_of_strings(obj):
Expand DownExpand Up@@ -560,12 +550,7 @@ def is_scalar(obj):

def is_numlike(obj):
"""return true if *obj* looks like a number"""
try:
obj + 1
except:
return False
else:
return True
return isinstance(obj, (numbers.Number, np.number))


def to_filehandle(fname, flag='rU', return_opened=False):
Expand Down
3 changes: 0 additions & 3 deletionslib/matplotlib/tests/test_cbook.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,9 +34,6 @@ def test_is_string_like():
y = np.array(y)
assert not cbook.is_string_like(y)

y = np.array(y, dtype=object)
assert cbook.is_string_like(y)


def test_is_sequence_of_strings():
y = ['a', 'b', 'c']
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp