Skip to content

Commit 21f1f88

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

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

pandas/tests/series/test_api.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
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)
16+
1617
import pandas.io.formats.printing as printing
1718
from pandas.util.testing import (assert_series_equal,
1819
ensure_clean)
@@ -250,6 +251,33 @@ def get_dir(s):
250251
results = get_dir(s)
251252
tm.assert_almost_equal(results, list(sorted(set(ok_for_cat))))
252253

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+
253281
def test_not_hashable(self):
254282
s_empty = Series()
255283
s = Series([1])

0 commit comments

Comments
 (0)