-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Series __finalized__ not correctly called in binary operators #13208
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
Comments
yeah it appears some paths don't call finalize; though you can't just call finalize for example on binary operations between 2 Series. This would have to be handled in the sub-class itself. We don't have the machinery to ignore this though. So I am suggesting that we DO call |
pull-requests welcome! |
@jreback I would like to attempt it. Based on what you have written, I have located the function def of finalize in generic.py. |
@pfrcks I think it means you need to change pandas/core/ops.py so that binary operations now call your brand new finalize |
@jdfekete That makes more sense. Thanks. Will look into it. |
so to clarify
would prob work. So the result in both cases is a |
I am not sure. Looking in ops.py on the So far, the operators are not passed to the |
that's exactly what needs to be one, |
Same issue, different contextCode Sampleimport pandas
# subclass series and define property 'meta' to be passed on
class S(pandas.Series):
_metadata = ['meta']
@property
def _constructor(self):
return S
# create new instance of Series subclass and set custom property
x = S(range(3))
x.meta = 'test'
# 'meta' gets passed on to slice, as expected
print(x[1:].meta)
# calculation results
print((x * 2).meta) Problem descriptionThe documentation states: See http://pandas.pydata.org/pandas-docs/stable/internals.html#define-original-properties. I think multiplication / adding etc. are also manipulation results. This should be discussed with others who are already subclassing Pandas classes and are making use of _metadata. Expected OutputThe property is expected to be passed on to the calculation result. Output of
|
My workaround: Always call @property
def _constructor(self):
def f(*args, **kwargs):
# workaround for https://github.com/pandas-dev/pandas/issues/13208
return MySubclass(*args, **kwargs).__finalize__(self)
return f |
Which module contains the operations part? Like add I would love to be able to contribute. |
This is fixed in master, may need a dedicated test |
Expected Output
In all cases, the metadata 'x' should be transferred from the passed values when applying binary operators.
When the right-hand value is a constant, the left-hand value metadata should be used in finalize for arithmetic operators, just like it is for Boolean binary operators.
When two series are used in binary operators, some resolution should be possible in finalize.
I would pass the second (right-hand) value by calling finalize(self, other=other), leaving the resolution to the derived class implementer, but there might be a smarter approach.
output of
pd.show_versions()
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-59-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.18.1
nose: 1.3.7
pip: None
setuptools: 20.2.2
Cython: 0.24
numpy: 1.11.0
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 4.0.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5.2
matplotlib: 1.5.0
openpyxl: 2.2.6
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.7.7
lxml: 3.4.4
bs4: 4.4.1
html5lib: 0.9999999
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: None
The text was updated successfully, but these errors were encountered: