Skip to content
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

Accessor Recipe - Style Question #16890

Closed
jbrockmendel opened this issue Jul 12, 2017 · 3 comments
Closed

Accessor Recipe - Style Question #16890

jbrockmendel opened this issue Jul 12, 2017 · 3 comments
Labels
Internals Related to non-user accessible pandas implementation

Comments

@jbrockmendel
Copy link
Member

Following up on discussion in #14781 , I am unifying the code that creates the str, cat, and dt accessors, and making/documenting a recipe for creating custom accessors. Two questions before I push forward, both revolving around methods like DataFrame._add_series_or_dataframe_operations (slightly different case, but close enough) that are called immediately after the class definitions, then never needed again.

  1. Are these needed in the user-facing namespace for some reason? If not, can we wedge them into _dir_deletions? I know the leading underscore makes it private, but dir(pd.DataFrame) and dir(pd.Series) have 444 and 441 members respectively. This gets pretty imposing.

  2. In many cases these methods are called immediately after the class definition, but others like ops.add_special_arithmetic_methods will be easy to miss if you don't know to look for it. One alternative that I am considering for the Accessors is applying a decorator to a class. Effectively replace

class Foo:
[...]

Foo._setup_methods(["bar", baz"])

with

@_setup_methods(["bar", "baz"])
class Foo:
[...]

The question being: is there a convention against using the latter approach?

@jreback
Copy link
Contributor

jreback commented Jul 12, 2017

  1. Are these needed in the user-facing namespace for some reason? If not, can we wedge them into _dir_deletions? I know the leading underscore makes it private, but dir(pd.DataFrame) and dir(pd.Series) have 444 and 441 members respectively. This gets pretty imposing.

not sure what you are mean here. accessor are by-definition namespaces that make the discovery easier and much more geared to the dtype.

  1. In many cases these methods are called immediately after the class definition, but others like ops.add_special_arithmetic_methods will be easy to miss if you don't know to look for it. One alternative that I am considering for the Accessors is applying a decorator to a class. Effectively replace

Why is this a problem? There are methods that are generically implemented which belong only to Series, only to DataFrame, to both (and possibly include Panels). So these are layered inclusion methods. You can certainly refactoror, not sure if the decorator syntax is better here. Pls make sweeping changes in separate PR's

@jreback
Copy link
Contributor

jreback commented Jul 12, 2017

closing this. You can comment on the other issues is prob easier.

@jreback jreback closed this as completed Jul 12, 2017
@jreback jreback added the Internals Related to non-user accessible pandas implementation label Jul 12, 2017
@shoyer
Copy link
Member

shoyer commented Jul 12, 2017

The question being: is there a convention against using the latter approach?

I think switching to decorators would be a welcome cleanup (but indeed, please save it for a separate PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

No branches or pull requests

3 participants