|
10 | 10 | from pandas import Index, Series, DataFrame, date_range
|
11 | 11 | from pandas.core.indexes.datetimes import Timestamp
|
12 | 12 |
|
13 |
| -from pandas.compat import range |
| 13 | +from pandas.compat import range, lzip, isidentifier, string_types |
14 | 14 | from pandas import compat
|
15 | 15 | import pandas.io.formats.printing as printing
|
16 | 16 | from pandas.util.testing import (assert_series_equal,
|
@@ -234,6 +234,33 @@ def test_tab_completion(self):
|
234 | 234 | assert 'str' not in dir(s)
|
235 | 235 | assert 'dt' in dir(s) # as it is a datetime categorical
|
236 | 236 |
|
| 237 | + @pytest.mark.parametrize("index", [ |
| 238 | + tm.makeUnicodeIndex(10), |
| 239 | + tm.makeStringIndex(10), |
| 240 | + tm.makeCategoricalIndex(10), |
| 241 | + Index(['foo', 'bar', 'baz'] * 2), |
| 242 | + tm.makeDateIndex(10), |
| 243 | + tm.makePeriodIndex(10), |
| 244 | + tm.makeTimedeltaIndex(10), |
| 245 | + tm.makeIntIndex(10), |
| 246 | + tm.makeUIntIndex(10), |
| 247 | + tm.makeIntIndex(10), |
| 248 | + tm.makeFloatIndex(10), |
| 249 | + Index([True, False]), |
| 250 | + Index(['a{}'.format(i) for i in range(101)]), |
| 251 | + pd.MultiIndex.from_tuples(lzip('ABCD', 'EFGH')), |
| 252 | + pd.MultiIndex.from_tuples(lzip([0, 1, 2, 3], 'EFGH')), ]) |
| 253 | + def test_index_tab_completion(self, index): |
| 254 | + # dir contains string-like values of the Index. |
| 255 | + s = pd.Series(index=index) |
| 256 | + dir_s = dir(s) |
| 257 | + for i, x in enumerate(s.index.unique(level=0)): |
| 258 | + if i < 100: |
| 259 | + assert (not isinstance(x, string_types) or |
| 260 | + not isidentifier(x) or x in dir_s) |
| 261 | + else: |
| 262 | + assert x not in dir_s |
| 263 | + |
237 | 264 | def test_not_hashable(self):
|
238 | 265 | s_empty = Series()
|
239 | 266 | s = Series([1])
|
|
0 commit comments