|
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, Categorical, period_range, timedelta_range,
|
15 | 15 | DatetimeIndex, PeriodIndex, TimedeltaIndex)
|
16 | 16 | import pandas.io.formats.printing as printing
|
@@ -250,6 +250,33 @@ def get_dir(s):
|
250 | 250 | results = get_dir(s)
|
251 | 251 | tm.assert_almost_equal(results, list(sorted(set(ok_for_cat))))
|
252 | 252 |
|
| 253 | + @pytest.mark.parametrize("index", [ |
| 254 | + tm.makeUnicodeIndex(10), |
| 255 | + tm.makeStringIndex(10), |
| 256 | + tm.makeCategoricalIndex(10), |
| 257 | + Index(['foo', 'bar', 'baz'] * 2), |
| 258 | + tm.makeDateIndex(10), |
| 259 | + tm.makePeriodIndex(10), |
| 260 | + tm.makeTimedeltaIndex(10), |
| 261 | + tm.makeIntIndex(10), |
| 262 | + tm.makeUIntIndex(10), |
| 263 | + tm.makeIntIndex(10), |
| 264 | + tm.makeFloatIndex(10), |
| 265 | + Index([True, False]), |
| 266 | + Index(['a{}'.format(i) for i in range(101)]), |
| 267 | + pd.MultiIndex.from_tuples(lzip('ABCD', 'EFGH')), |
| 268 | + pd.MultiIndex.from_tuples(lzip([0, 1, 2, 3], 'EFGH')), ]) |
| 269 | + def test_index_tab_completion(self, index): |
| 270 | + # dir contains string-like values of the Index. |
| 271 | + s = pd.Series(index=index) |
| 272 | + dir_s = dir(s) |
| 273 | + for i, x in enumerate(s.index.unique(level=0)): |
| 274 | + if i < 100: |
| 275 | + assert (not isinstance(x, string_types) or |
| 276 | + not isidentifier(x) or x in dir_s) |
| 277 | + else: |
| 278 | + assert x not in dir_s |
| 279 | + |
253 | 280 | def test_not_hashable(self):
|
254 | 281 | s_empty = Series()
|
255 | 282 | s = Series([1])
|
|
0 commit comments