Skip to content

Commit bee67d1

Browse files
author
Martin Journois
committed
TST: ADD test on Series index auto-completion
1 parent 4ea43bf commit bee67d1

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

pandas/tests/series/test_api.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas import Index, Series, DataFrame, date_range
1111
from pandas.core.indexes.datetimes import Timestamp
1212

13-
from pandas.compat import range
13+
from pandas.compat import range, lzip, isidentifier, string_types
1414
from pandas import (compat, Categorical, period_range, timedelta_range,
1515
DatetimeIndex, PeriodIndex, TimedeltaIndex)
1616
import pandas.io.formats.printing as printing
@@ -250,6 +250,33 @@ def get_dir(s):
250250
results = get_dir(s)
251251
tm.assert_almost_equal(results, list(sorted(set(ok_for_cat))))
252252

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+
253280
def test_not_hashable(self):
254281
s_empty = Series()
255282
s = Series([1])

0 commit comments

Comments
 (0)