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
cbook.is_sequence_of_strings knows string objects #4358
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cbook.is_sequence_of_strings recognizes string objects | ||
`````````````````````````````````````````````````````` | ||
|
||
This is primarily how pandas stores a sequence of strings. | ||
|
||
import pandas as pd | ||
import matplotlib.cbook as cbook | ||
|
||
a = np.array(['a', 'b', 'c']) | ||
print(cbook.is_sequence_of_strings(a)) # True | ||
|
||
a = np.array(['a', 'b', 'c'], dtype=object) | ||
print(cbook.is_sequence_of_strings(a)) # True | ||
|
||
s = pd.Series(['a', 'b', 'c']) | ||
print(cbook.is_sequence_of_strings(s)) # True | ||
|
||
Previously, the last two prints returned false. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -783,8 +783,12 @@ def is_sequence_of_strings(obj): | |
""" | ||
if not iterable(obj): | ||
return False | ||
if is_string_like(obj): | ||
return False | ||
if is_string_like(obj) and not isinstance(obj, np.ndarray): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Defn: is_string_like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we can not import pandas directly in core matplotlib for both technical On Tue, Apr 28, 2015, 11:31 Phillip Cloud notifications@github.com wrote:
|
||
try: | ||
obj = obj.values | ||
except AttributeError: | ||
# not pandas | ||
return False | ||
for o in obj: | ||
if not is_string_like(o): | ||
return False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not catch new
pd.Series
as they are no longer ndarray sub-classesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like
or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll fix. I now see that Pandas has moved 3 major versions since I encountered this. I need to do a better job keeping all my virtual environments up-to-date.