-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: _dir_additions returns also the first level of a MultiIndex #16326
Changes from all commits
6840e11
4ea43bf
bee67d1
edb184a
a46e9e9
829bdf4
4ee5b9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from pandas import Index, Series, DataFrame, date_range | ||
from pandas.core.indexes.datetimes import Timestamp | ||
|
||
from pandas.compat import range | ||
from pandas.compat import range, lzip, isidentifier, string_types | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a test that has 101 columns and assert first 100 there and last 1 is not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you do thsi There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
from pandas import (compat, Categorical, period_range, timedelta_range, | ||
DatetimeIndex, PeriodIndex, TimedeltaIndex) | ||
import pandas.io.formats.printing as printing | ||
|
@@ -250,6 +250,33 @@ def get_dir(s): | |
results = get_dir(s) | ||
tm.assert_almost_equal(results, list(sorted(set(ok_for_cat)))) | ||
|
||
@pytest.mark.parametrize("index", [ | ||
tm.makeUnicodeIndex(10), | ||
tm.makeStringIndex(10), | ||
tm.makeCategoricalIndex(10), | ||
Index(['foo', 'bar', 'baz'] * 2), | ||
tm.makeDateIndex(10), | ||
tm.makePeriodIndex(10), | ||
tm.makeTimedeltaIndex(10), | ||
tm.makeIntIndex(10), | ||
tm.makeUIntIndex(10), | ||
tm.makeIntIndex(10), | ||
tm.makeFloatIndex(10), | ||
Index([True, False]), | ||
Index(['a{}'.format(i) for i in range(101)]), | ||
pd.MultiIndex.from_tuples(lzip('ABCD', 'EFGH')), | ||
pd.MultiIndex.from_tuples(lzip([0, 1, 2, 3], 'EFGH')), ]) | ||
def test_index_tab_completion(self, index): | ||
# dir contains string-like values of the Index. | ||
s = pd.Series(index=index) | ||
dir_s = dir(s) | ||
for i, x in enumerate(s.index.unique(level=0)): | ||
if i < 100: | ||
assert (not isinstance(x, string_types) or | ||
not isidentifier(x) or x in dir_s) | ||
else: | ||
assert x not in dir_s | ||
|
||
def test_not_hashable(self): | ||
s_empty = Series() | ||
s = Series([1]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add an asv that does dir() on a Series/DataFrame with say 10000 elements (we might already have one of these)