Description
-
[ x ] I have checked that this issue has not already been reported.
-
[ x ] I have confirmed this bug exists on the latest version of pandas.
-
[ x ] (optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
import pandas as pd
import functools
class SubclassedSeries(pd.Series):
@property
def _constructor(self):
return SubclassedSeries
@property
def _constructor_expanddim(self):
return SubclassedDataFrame
class SubclassedDataFrame(pd.DataFrame):
_metadata = ['my_extra_data']
def __init__(self, my_extra_data, *args, **kwargs):
self.my_extra_data = my_extra_data
super().__init__(*args, **kwargs)
@property
def _constructor(self):
return functools.partial(self.__class__, self.my_extra_data)
@property
def _constructor_sliced(self):
return SubclassedSeries
x = SubclassedDataFrame("some_data", {"A":[1,2,3], "B":[4,5,6]})
x*2
Problem description
This code raises an exception, ultimately because function _dispatch_frame_op
in \pandas\core\frame.py returns type(self)(bm)
. Shouldn't instead return self._constructor(bm)
?
Expected Output
A B
0 2 8
1 4 10
2 6 12
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 5f648bf
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-81-generic
Version : #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.3.2
numpy : 1.20.1
pytz : 2019.3
dateutil : 2.7.3
pip : 21.0.1
setuptools : 45.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.21.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.4
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None