@@ -139,8 +139,12 @@ def _obj_with_exclusions(self):
139
139
return self .obj
140
140
141
141
def __getattr__ (self , attr ):
142
+ if attr in self .obj :
143
+ return self [attr ]
144
+
142
145
if hasattr (self .obj , attr ) and attr != '_cache' :
143
146
return self ._make_wrapper (attr )
147
+
144
148
raise AttributeError ("'%s' object has no attribute '%s'" %
145
149
(type (self ).__name__ , attr ))
146
150
@@ -1644,3 +1648,27 @@ def numpy_groupby(data, labels, axis=0):
1644
1648
group_sums = np .add .reduceat (ordered_data , groups_at , axis = axis )
1645
1649
1646
1650
return group_sums
1651
+
1652
+ from pandas .util import py3compat
1653
+ import sys
1654
+
1655
+ def install_ipython_completers (): # pragma: no cover
1656
+ """Register the DataFrame type with IPython's tab completion machinery, so
1657
+ that it knows about accessing column names as attributes."""
1658
+ from IPython .utils .generics import complete_object
1659
+
1660
+ @complete_object .when_type (DataFrameGroupBy )
1661
+ def complete_dataframe (obj , prev_completions ):
1662
+ return prev_completions + [c for c in obj .obj .columns \
1663
+ if isinstance (c , basestring ) and py3compat .isidentifier (c )]
1664
+
1665
+
1666
+ # Importing IPython brings in about 200 modules, so we want to avoid it unless
1667
+ # we're in IPython (when those modules are loaded anyway).
1668
+ if "IPython" in sys .modules : # pragma: no cover
1669
+ try :
1670
+ install_ipython_completers ()
1671
+ except Exception :
1672
+ pass
1673
+
1674
+
0 commit comments