Skip to content

Subclassing Series with an original attribute #17726

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

Closed
pirsquared opened this issue Sep 30, 2017 · 1 comment
Closed

Subclassing Series with an original attribute #17726

pirsquared opened this issue Sep 30, 2017 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request Subclassing Subclassing pandas objects

Comments

@pirsquared
Copy link

pirsquared commented Sep 30, 2017

See SO post
https://stackoverflow.com/q/46498784/2336654

Code Sample, a copy-pastable example if possible

from pandas import Series


class Xseries(Series):
    _metadata = ['attr']

    @property
    def _constructor(self):
        return Xseries

    def __init__(self, *args, **kwargs):
        self.attr = kwargs.pop('attr', 0)
        super().__init__(*args, **kwargs)

s = Xseries([1, 2, 3], attr=3)

Problem description

According to https://pandas.pydata.org/pandas-docs/stable/internals.html#define-original-properties
I should be able to define an original property and have it passed on when a new object is constructed.

This works

s.mul(2).attr

3

While this doesn't

s.__mul__(2).attr

0

Expected Output

I expected both output to be 3

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.3.0
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.18.1
xarray: 0.9.5
IPython: 6.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
feather: 0.4.0
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.999999999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: 0.4.0

@chris-b1
Copy link
Contributor

Duplicate of #13208 - PR to address welcome

@chris-b1 chris-b1 added the Duplicate Report Duplicate issue or pull request label Sep 30, 2017
@chris-b1 chris-b1 added this to the No action milestone Sep 30, 2017
@jorisvandenbossche jorisvandenbossche added the Subclassing Subclassing pandas objects label Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Subclassing Subclassing pandas objects
Projects
None yet
Development

No branches or pull requests

3 participants