Subclassing is lost when using DataFrame.apply #19822
Labels
Compat
pandas objects compatability with Numpy or Python functions
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Subclassing
Subclassing pandas objects
Milestone
Code Sample, a copy-pastable example if possible
Problem description
The class type of the applied objects should still be
<class '__main__.ExtendedSeries'>
instead of going back to<class 'pandas.core.series.Series'>
.The issue here is that in
pandas.core.apply
, whenever the returning objects are generated, they are declared asDataFrame
andSeries
instead ofself.obj._constructor
andself.obj._constructor_slice
.This behaviour makes it difficult to properly work with subclasses from pandas.
Expected Output
Following the initial code example, the expected output should be:
(note the change in the last printed lines)
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 17.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.21.1
pytest: None
pip: 9.0.1
setuptools: 38.4.0
Cython: None
numpy: 1.14.0
scipy: 0.18.1
pyarrow: None
xarray: None
IPython: 5.4.1
sphinx: 1.6.6
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.5.1
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: