Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cbook.is_sequence_of_strings knows string objects
**Issue** `cbook.is_sequence_of_strings` cannot tell of a pandas series is contains strings. Pandas series are numpy arrays of type `object`. **Problem** `cbook.is_sequence_of_strings` uses `cbook.is_string_like` to dismiss strings as not sequences of strings. However, numpy string arrays of `dtype=object` are string-like since they support string concatenation. **Solution** Do not dismiss an `ndarray` if it appears string-like, go ahead and peak inside.
- Loading branch information
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cbook.is_sequence_of_strings recognizes string objects | ||
`````````````````````````````````````````````````````` | ||
|
||
This is primarily how pandas stores a sequence of strings. | ||
|
||
>>> import pandas as pd | ||
>>> import matplotilb.cbook as cbook | ||
>>> a = np.array(['a', 'b', 'c']) | ||
>>> cbook.sequence_of_strings(a) | ||
False | ||
>>> a = np.array(['a', 'b', 'c'], dtype=object) | ||
>>> cbook.sequence_of_strings(a) | ||
True | ||
>>> s = pd.Series(['a', 'b', 'c])] | ||
>>> cbook.sequence_of_strings(s) | ||
True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters