Skip to content

API: rename _prop_attributes to __finalize__ (in NDFrame) #5205

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 15, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Oct 13, 2013

  • rename _propogate_attributes to _metadata (in NDFrame)
  • change methods which directly pass metadata to use finalize

These provide a simple mechanism for meta data propagation, which
can be overriden in subclasses if desired. Currently these only do non-ambiguous
propagation.

makes #60, #2485 easier

@jreback
Copy link
Contributor Author

jreback commented Oct 13, 2013

@jtratner

I was actually toying with the idea of having __finalize__ have a signature like this:

def __finalize__(self, other, method=None):
.....

then a sub-class (or even in the current implementation of ``finalize`) you could dispatch on the method (which would be the name of the calling method) and do something interesting

@jtratner
Copy link
Contributor

that's similar to what numpy does. Let's be clear about lifecycle for NDFrame:

__new__ --> not used (just object's __new__)
__init__ --> called to reconstruct object, no access to metadata of previous
__finalize__ --> called after __init__ is done initializing after things like arithmetic, sorting, and slicing that generate either same type or constructorsliced?

So if you do df["A"], would that call __finalize__? what about df.loc or other structures like that? (or the methods that promote upwards)?

__init__ doesn't return anything, should __finalize__ return self?

@jtratner
Copy link
Contributor

also which __finalize__ gets called on df["A"]? I'm assuming it's whatever is on the sliced constructor?

@jtratner
Copy link
Contributor

I'm a fan of having it return self, looks nicer in the code too.

@jtratner
Copy link
Contributor

btw - to keep in mind, from the Python docs on magic methods:

__*__
System-defined names. These names are defined by the interpreter and its implementation (including the standard library). Current system names are discussed in the Special method names section and elsewhere. More will likely be defined in future versions of Python. Any use of __*__ names, in any context, that does not follow explicitly documented use, is subject to breakage without warning.

http://docs.python.org/2/reference/lexical_analysis.html#reserved-classes-of-identifiers

I'm guessing that numpy is popular enough for them not to worry about it 😄

I still like __finalize__ though.

     rename _propogate_attributes to _metadata (in NDFrame)
     change methods which directly pass metadata to use __finalize__

     These provide a simple mechanism for meta data propagation, which
     can be overriden in subclasses if desired
@jtratner
Copy link
Contributor

Does this have a performance hit? I'd guess that it would be minimal.

@jreback
Copy link
Contributor Author

jreback commented Oct 14, 2013

it's already in there (and minimal)
just per construction

jreback added a commit that referenced this pull request Oct 15, 2013
API: rename _prop_attributes to __finalize__ (in NDFrame)
@jreback jreback merged commit 0a3dbf7 into pandas-dev:master Oct 15, 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.

2 participants