Skip to content

Commit

Permalink
Merge pull request #7362 from mbyt/complete_on_numpy_struct_itself
Browse files Browse the repository at this point in the history
Allow completion on the numpy struct itself
  • Loading branch information
minrk committed Jan 3, 2015
2 parents a6ac0e7 + 1ec19a2 commit a0e7fd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion IPython/core/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,8 @@ def get_keys(obj):
return list(obj.keys())
except Exception:
return []
elif _safe_isinstance(obj, 'numpy', 'ndarray'):
elif _safe_isinstance(obj, 'numpy', 'ndarray') or\
_safe_isinstance(obj, 'numpy', 'void'):
return obj.dtype.names or []
return []

Expand Down
14 changes: 14 additions & 0 deletions IPython/core/tests/test_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,20 @@ def test_struct_array_key_completion():
_, matches = complete(line_buffer="d['")
nt.assert_in("hello", matches)
nt.assert_in("world", matches)
# complete on the numpy struct itself
dt = numpy.dtype([('my_head', [('my_dt', '>u4'), ('my_df', '>u4')]),
('my_data', '>f4', 5)])
x = numpy.zeros(2, dtype=dt)
ip.user_ns['d'] = x[1]
_, matches = complete(line_buffer="d['")
nt.assert_in("my_head", matches)
nt.assert_in("my_data", matches)
# complete on a nested level
with greedy_completion():
ip.user_ns['d'] = numpy.zeros(2, dtype=dt)
_, matches = complete(line_buffer="d[1]['my_head']['")
nt.assert_true(any(["my_dt" in m for m in matches]))
nt.assert_true(any(["my_df" in m for m in matches]))


@dec.skip_without('pandas')
Expand Down

0 comments on commit a0e7fd5

Please sign in to comment.