Skip to content

API: provide __dir__ method (and local context) for tab completion / remove ipython completers code #5050

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

Merged
merged 1 commit into from
Oct 1, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Sep 30, 2013

closes #4501

this removes the ipython completers code and instead defines __dir__,
with a _local_dir that a class can override

NDFrame objects will have a pre-defined local of the info_axis (e.g. columns in a DataFrame)

for example:

In [1]: df = DataFrame(columns=list('ABC'))

In [2]: df.
Display all 199 possibilities? (y or n)
df.A                  df.at_time            df.corrwith           df.eq                 df.groupby            df.itertuples         df.min                df.reindex            df.shape              df.to_dict            df.tshift
df.B                  df.axes               df.count              df.eval               df.gt                 df.ix                 df.mod                df.reindex_axis       df.shift              df.to_excel           df.tz_convert
df.C                  df.between_time       df.cov                df.ffill              df.head               df.join               df.mul                df.reindex_like       df.skew               df.to_hdf             df.tz_localize
df.T                  df.bfill              df.cummax             df.fillna             df.hist               df.keys               df.multiply           df.rename             df.sort               df.to_html            df.unstack
df.abs                df.blocks             df.cummin             df.filter             df.iat                df.kurt               df.ndim               df.rename_axis        df.sort_index         df.to_json            df.update
df.add                df.boxplot            df.cumprod            df.first              df.icol               df.kurtosis           df.ne                 df.reorder_levels     df.sortlevel          df.to_latex           df.values
df.add_prefix         df.clip               df.cumsum             df.first_valid_index  df.idxmax             df.last               df.pct_change         df.replace            df.squeeze            df.to_panel           df.var
df.add_suffix         df.clip_lower         df.delevel            df.floordiv           df.idxmin             df.last_valid_index   df.pivot              df.resample           df.stack              df.to_period          df.where
df.align              df.clip_upper         df.describe           df.from_csv           df.iget_value         df.le                 df.pivot_table        df.reset_index        df.std                df.to_pickle          df.xs
df.all                df.columns            df.diff               df.from_dict          df.iloc               df.load               df.plot               df.rfloordiv          df.sub                df.to_records         
df.any                df.combine            df.div                df.from_items         df.index              df.loc                df.pop                df.rmod               df.subtract           df.to_sparse          
df.append             df.combineAdd         df.divide             df.from_records       df.info               df.lookup             df.pow                df.rmul               df.sum                df.to_sql             
df.apply              df.combineMult        df.dot                df.ftypes             df.insert             df.lt                 df.prod               df.rpow               df.swapaxes           df.to_stata           
df.applymap           df.combine_first      df.drop               df.ge                 df.interpolate        df.mad                df.product            df.rsub               df.swaplevel          df.to_string          
df.as_blocks          df.compound           df.drop_duplicates    df.get                df.irow               df.mask               df.quantile           df.rtruediv           df.tail               df.to_timestamp       
df.as_matrix          df.consolidate        df.dropna             df.get_dtype_counts   df.isin               df.max                df.query              df.save               df.take               df.to_wide            
df.asfreq             df.convert_objects    df.dtypes             df.get_ftype_counts   df.iteritems          df.mean               df.radd               df.select             df.to_clipboard       df.transpose          
df.astype             df.copy               df.duplicated         df.get_value          df.iterkv             df.median             df.rank               df.set_index          df.to_csv             df.truediv            
df.at                 df.corr               df.empty              df.get_values         df.iterrows           df.merge              df.rdiv               df.set_value          df.to_dense           df.truncate           

Only provide 'public' methods
"""
ld = self._local_dir()
return sorted([ d for d in dir(type(self)) if not d.startswith('_') ]) + ld
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need type(self), can just use self

also ipython provides control over completion of things starting with _, maybe we should just do

ld = [c for c in self.info_axis if isinstance(c, compat.string_types) and compat.isidentifier(c)]
dir(self) + ld

because we still need to complete col names

not sure if info_axis is public, doubt it....but u get the idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look in core/generic.py/_local_dir...that's exactly what I did (so that inheriterts can just override that)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh duh.... 😪

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm -1 on blocking users from introspecting private methods (like this
does). Makes it much harder to debug things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy enough.....I believe @cpcloud is right that ipython does that though (but the user can always call directly)

@jreback
Copy link
Contributor Author

jreback commented Sep 30, 2013

@jtratner done

@jreback
Copy link
Contributor Author

jreback commented Sep 30, 2013

@jtratner @cpcloud anything further, merge?

@jtratner
Copy link
Contributor

I want to look again but can't right now.

Only provide 'public' methods
"""
ld = self._local_dir()
return sorted(dir(type(self))) + ld
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think this should be:

object.__dir__(self) + self._local_dir()

@jtratner
Copy link
Contributor

actually, aside from the one change I think we should make I'm fine with it. If you want to do sorted that's fine too. But it needs to be list(sorted, because sorted returns generator in python 3

@jreback
Copy link
Contributor Author

jreback commented Sep 30, 2013

not sure sorted even matters (as I belive ipython does but...ok)

@jreback
Copy link
Contributor Author

jreback commented Sep 30, 2013

@cpcloud object__dir__ doesn't exist by default, dir must do some kind of fallback with it

jreback added a commit that referenced this pull request Oct 1, 2013
API: provide __dir__ method (and local context) for tab completion / remove ipython completers code
@jreback jreback merged commit 09b3c0a into pandas-dev:master Oct 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tab complete lurking groupby methods
3 participants