-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat: support Index.to_frame()
#894
base: main
Are you sure you want to change the base?
Changes from 6 commits
b62f1ca
ef7eaf8
cd97a45
860f370
8761d8a
c68a5f5
7c2e1b0
e9bffa8
0f2e291
2e1afff
e376b44
31f3db8
e813c61
32eb06c
60bea0a
ec97d72
af9f7a4
b212126
9c31fb3
266feae
43f826c
5d388da
c368362
3d2ba36
2966f08
ab2753e
777ff7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,32 @@ def from_frame( | |
index = Index(frame._block) | ||
index._linked_frame = frame | ||
return index | ||
|
||
def to_frame( | ||
self, index: bool = True, name: blocks.Label | None = None | ||
) -> bigframes.dataframe.DataFrame: | ||
import numpy as np | ||
provided_name = name if name else self.name | ||
provided_index = self.values if index else np.arange(len(self.values)) | ||
result = bigframes.dataframe.DataFrame({provided_name: self.values}, index= provided_index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the index is a MultiIndex, the resulting DataFrame will need to have multiple columns (and names will need to be a list-like with length equal to the multi-index level depth). |
||
if index: # matching pandas behavior | ||
result.index.name = self.name | ||
return result | ||
|
||
def to_frame( | ||
mattyopl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self, index: bool = True, name: blocks.Label | None = None | ||
) -> bigframes.dataframe.DataFrame: | ||
import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put the import at the top of the file for easier management. Actually numpy is already imported in the file. Import in the method only to avoid circular imports. |
||
|
||
provided_name = name if name else self.name | ||
provided_index = self.values if index else np.arange(len(self.values)) | ||
result = bigframes.dataframe.DataFrame( | ||
{provided_name: self.values}, index=provided_index | ||
) | ||
if index: # matching pandas behavior | ||
result.index.name = self.name | ||
|
||
return result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redefinition |
||
|
||
@property | ||
def _session(self): | ||
|
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.
Just provide
None
if want default sequential index. np.arrange may create a very large in-memory array here if the original index is large (some BigFrames objects have billions of rows).