Skip to content

Commit

Permalink
BUG: Fix dir(interval_index), closes pandas-dev#27571
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Jul 30, 2019
1 parent 0fd888c commit 6d8e9ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.1.rst
Expand Up @@ -78,7 +78,7 @@ Strings

Interval
^^^^^^^^

- Bug in :class:`IntervalIndex` where `dir(obj)` would raise ``ValueError`` (:issue:`27571`)
-
-
-
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/strings.py
Expand Up @@ -1953,8 +1953,11 @@ def _validate(data):
values = getattr(data, "values", data) # Series / Index
values = getattr(values, "categories", values) # categorical / normal

# missing values obfuscate type inference -> skip
inferred_dtype = lib.infer_dtype(values, skipna=True)
inferred_dtype = None
if isinstance(values, np.ndarray):
# exclude e.g. IntervalArray, which will cause infer_dtype to raise
# missing values obfuscate type inference -> skip
inferred_dtype = lib.infer_dtype(values, skipna=True)

if inferred_dtype not in allowed_types:
raise AttributeError("Can only use .str accessor with string values!")
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/interval/test_interval.py
Expand Up @@ -1095,3 +1095,10 @@ def test_is_all_dates(self):
)
year_2017_index = pd.IntervalIndex([year_2017])
assert not year_2017_index.is_all_dates


def test_dir():
# GH#27571 dir(interval_index) should not raise
index = IntervalIndex.from_arrays([0, 1], [1, 2])
result = dir(index)
assert "str" not in result

0 comments on commit 6d8e9ab

Please sign in to comment.