-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Stack/unstack do not return subclassed objects (GH15563) #18929
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #18929 +/- ##
==========================================
+ Coverage 91.52% 91.54% +0.02%
==========================================
Files 147 147
Lines 48775 48775
==========================================
+ Hits 44639 44651 +12
+ Misses 4136 4124 -12
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks pretty good.
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -345,7 +345,8 @@ Reshaping | |||
- Fixed construction of a :class:`Series` from a ``dict`` containing ``NaN`` as key (:issue:`18480`) | |||
- Bug in :func:`Series.rank` where ``Series`` containing ``NaT`` modifies the ``Series`` inplace (:issue:`18521`) | |||
- Bug in :func:`Dataframe.pivot_table` which fails when the ``aggfunc`` arg is of type string. The behavior is now consistent with other methods like ``agg`` and ``apply`` (:issue:`18713`) | |||
|
|||
- Bug in :func:`DataFrame.stack`, `DataFrame.unstack`, `Series.unstack` which were not returning subclasses (:issue:`15563`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to have the :func:
for each one
pandas/core/reshape/reshape.py
Outdated
the default fill value for that data type, NaN for float, NaT for | ||
datetimelike, etc. For integer types, by default data will converted to | ||
float and missing values will be set to NaN. | ||
constructor : object, default DataFrame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
pandas/core/reshape/reshape.py
Outdated
@@ -85,6 +100,13 @@ def __init__(self, values, index, level=-1, value_columns=None, | |||
self.values = values | |||
self.value_columns = value_columns | |||
self.fill_value = fill_value | |||
if constructor is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I hate if then's like this. any better way?
pandas/core/reshape/reshape.py
Outdated
@@ -476,12 +499,13 @@ def _unstack_frame(obj, level, fill_value=None): | |||
unstacker = partial(_Unstacker, index=obj.index, | |||
level=level, fill_value=fill_value) | |||
blocks = obj._data.unstack(unstacker) | |||
klass = type(obj) | |||
klass = obj._constructor | |||
return klass(blocks) | |||
else: | |||
unstacker = _Unstacker(obj.values, obj.index, level=level, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be a slightly bigger change, but could pass obj
to _Unstacker
directly and might be simpler.
53c209d
to
2d3683b
Compare
Hello @rockg! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 11, 2018 at 14:08 Hours UTC |
Tried to incorporate obj into |
2d3683b
to
f3c71d9
Compare
can you revert back to what you had. that was ok for now. its not as clear this way. |
f3c71d9
to
c554784
Compare
c554784
to
16d82c5
Compare
All green. |
thanks @rockg |
git diff upstream/master -u -- "*.py" | flake8 --diff
Basically picked from #15655 to support stack/unstack in subclassed DataFrames and Series.