Skip to content

Commit b621244

Browse files
author
Martin Journois
committed
TST: Add test on DataFrame columns auto-completion
1 parent a833cc1 commit b621244

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/frame/test_api.py

+18
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ def test_column_contains_typeerror(self):
128128
except TypeError:
129129
pass
130130

131+
def test_tab_completion(self):
132+
# DataFrame whose columns are identifiers shall have them in __dir__.
133+
df = pd.DataFrame([list('abcd'), list('efgh')], columns=list('ABCD'))
134+
for key in list('ABCD'):
135+
assert key in dir(df)
136+
assert isinstance(df.__getitem__('A'), pd.Series)
137+
138+
# DataFrame whose first-level columns are identifiers shall have
139+
# them in __dir__.
140+
df = pd.DataFrame(
141+
[list('abcd'), list('efgh')],
142+
columns=pd.MultiIndex.from_tuples(list(zip('ABCD', 'EFGH'))))
143+
for key in list('ABCD'):
144+
assert key in dir(df)
145+
for key in list('EFGH'):
146+
assert key not in dir(df)
147+
assert isinstance(df.__getitem__('A'), pd.DataFrame)
148+
131149
def test_not_hashable(self):
132150
df = self.klass([1])
133151
pytest.raises(TypeError, hash, df)

0 commit comments

Comments
 (0)