Skip to content

CLN: Remove Series._from_array #19893

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 9 commits into from
Feb 27, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test_frame_subclassing_and_inherit
  • Loading branch information
jaumebonet committed Feb 25, 2018
commit e27554ca6e397a18b638efc30b8e5fcecfbe96be
56 changes: 56 additions & 0 deletions pandas/tests/frame/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,59 @@ def strech(row):
result = df.apply(lambda x: [1, 2, 3], axis=1)
assert not isinstance(result, tm.SubclassedDataFrame)
tm.assert_series_equal(result, expected)

def test_frame_subclassing_and_inherit(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of these tests? this is another issue, yes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in a new PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote it to check that that approach would work now. I'll take it out.

# Subclass frame and series and ensure that data can be transfered between them
# on slicing GH#19883

class CustomSeries(Series):

def __init__(self, *args, **kw):
super(CustomSeries, self).__init__(*args, **kw)
self.extra_data = None

@property
def _constructor(self):
return CustomSeries

def __finalize__(self, other, method=None, **kwargs):
if method == "_inherit":
self.extra_data = other.extra_data
return self

class CustomDataFrame(DataFrame):
"""
Subclasses pandas DF, fills DF with simulation results, adds some
custom temporal data.
"""

def __init__(self, *args, **kw):
super(CustomDataFrame, self).__init__(*args, **kw)
self.extra_data = None

@property
def _constructor(self):
return CustomDataFrame

@property
def _constructor_sliced(self):
def f(*args, **kwargs):
return CustomSeries(*args, **kwargs).__finalize__(self, method='_inherit')
return f

data = {'col1': range(10),
'col2': range(10)}
cdf = CustomDataFrame(data)
cdf.extra_data = range(3)

# column
cdf_series = cdf.col1
assert cdf_series.extra_data == cdf.extra_data

# row
cdf_series = cdf.iloc[0]
assert cdf_series.extra_data == cdf.extra_data