|
15 | 15 | from StringIO import StringIO
|
16 | 16 | import csv
|
17 | 17 | import operator
|
| 18 | +import sys |
18 | 19 | import warnings
|
19 | 20 |
|
20 | 21 | from numpy import nan
|
@@ -550,7 +551,6 @@ def to_string(self, buf=None, columns=None, colSpace=None,
|
550 | 551 | nanRep='NaN', formatters=None, float_format=None,
|
551 | 552 | sparsify=True):
|
552 | 553 | from pandas.core.common import _format, adjoin
|
553 |
| - import sys |
554 | 554 |
|
555 | 555 | if buf is None: # pragma: no cover
|
556 | 556 | buf = sys.stdout
|
@@ -629,7 +629,6 @@ def info(self, verbose=True, buf=None):
|
629 | 629 | If False, don't print column count summary
|
630 | 630 | buf : writable buffer, defaults to sys.stdout
|
631 | 631 | """
|
632 |
| - import sys |
633 | 632 | if buf is None: # pragma: no cover
|
634 | 633 | buf = sys.stdout
|
635 | 634 |
|
@@ -3304,6 +3303,22 @@ def _homogenize(data, index, columns, dtype=None):
|
3304 | 3303 | def _put_str(s, space):
|
3305 | 3304 | return ('%s' % s)[:space].ljust(space)
|
3306 | 3305 |
|
| 3306 | +def install_ipython_completers(): |
| 3307 | + """Register the DataFrame type with IPython's tab completion machinery, so |
| 3308 | + that it knows about accessing column names as attributes.""" |
| 3309 | + from IPython.utils.generics import complete_object |
| 3310 | + |
| 3311 | + @complete_object.when_type(DataFrame) |
| 3312 | + def complete_dataframe(obj, prev_completions): |
| 3313 | + return prev_completions + [c for c in obj.columns \ |
| 3314 | + if py3compat.isidentifier(c)] |
| 3315 | + |
| 3316 | +# Importing IPython brings in about 200 modules, so we want to avoid it unless |
| 3317 | +# we're in IPython (when those modules are loaded anyway). |
| 3318 | +if "IPython" in sys.modules: |
| 3319 | + install_ipython_completers() |
| 3320 | + |
| 3321 | + |
3307 | 3322 | if __name__ == '__main__':
|
3308 | 3323 | import nose
|
3309 | 3324 | nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
|
|
0 commit comments