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