-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
BUG: Fix SparseFrameAccessor.to_dense return type #59967
BUG: Fix SparseFrameAccessor.to_dense return type #59967
Conversation
71a633d
to
fea6dd8
Compare
class SubclassedDataFrame(pd.DataFrame): | ||
@property | ||
def _constructor(self): | ||
return SubclassedDataFrame | ||
|
||
df = SubclassedDataFrame({"sparse": pd.arrays.SparseArray([1, 2])}) | ||
assert isinstance(df.sparse.to_dense(), SubclassedDataFrame) |
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.
class SubclassedDataFrame(pd.DataFrame): | |
@property | |
def _constructor(self): | |
return SubclassedDataFrame | |
df = SubclassedDataFrame({"sparse": pd.arrays.SparseArray([1, 2])}) | |
assert isinstance(df.sparse.to_dense(), SubclassedDataFrame) | |
df = tm.SubclassedDataFrame({"sparse": pd.arrays.SparseArray([1, 2])}) | |
assert isinstance(df.sparse.to_dense(), tm.SubclassedDataFrame) |
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, I didn't know it's already there.
@@ -369,10 +369,9 @@ def to_dense(self) -> DataFrame: | |||
1 1 | |||
2 0 | |||
""" | |||
from pandas import DataFrame | |||
|
|||
constructor = self._parent._constructor |
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.
Nit: Could you inline this on the return
line?
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.
Sure, done.
fea6dd8
to
10b2363
Compare
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 for the review. I amended the existing commit.
class SubclassedDataFrame(pd.DataFrame): | ||
@property | ||
def _constructor(self): | ||
return SubclassedDataFrame | ||
|
||
df = SubclassedDataFrame({"sparse": pd.arrays.SparseArray([1, 2])}) | ||
assert isinstance(df.sparse.to_dense(), SubclassedDataFrame) |
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, I didn't know it's already there.
@@ -369,10 +369,9 @@ def to_dense(self) -> DataFrame: | |||
1 1 | |||
2 0 | |||
""" | |||
from pandas import DataFrame | |||
|
|||
constructor = self._parent._constructor |
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.
Sure, done.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
Thanks @janezd |
doc/source/whatsnew/vX.X.X.rst
file