Skip to content
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: Add MultiIndex subclass. #596

Merged
merged 8 commits into from
Apr 10, 2024
Merged

feat: Add MultiIndex subclass. #596

merged 8 commits into from
Apr 10, 2024

Conversation

TrevorBergeron
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

Page not found · GitHub · GitHub
Skip to content
404 “This is not the web page you are looking for”
@TrevorBergeron TrevorBergeron requested review from a team as code owners April 8, 2024 23:29
@TrevorBergeron TrevorBergeron requested a review from shobsi April 8, 2024 23:29
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Apr 8, 2024
@TrevorBergeron TrevorBergeron requested review from GarrettWu and removed request for shobsi April 8, 2024 23:29
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. label Apr 8, 2024

def __init__(
# Overrided on __new__ to create subclasses like python does
def __new__(
self,
Copy link
Contributor

Choose a reason for hiding this comment

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

__new__ is a static method that takes cls as param instead of self.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -454,24 +475,27 @@ def __len__(self):
return self.shape[0]


# Index that mutates the originating dataframe/series
class FrameIndex(Index):
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a breaking change that we may not want to introduce right now. @tswast

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 am deleting a class yes, but it was more of an implementation detail of the Index class. Should only affect users if they were somehow depending on exact type or type name in their code, which would be very strange.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch @GarrettWu.

Given that we say ) -> Index: in the only method that would return such an object and we don't explicitly document FrameIndex, I'm okay overlooking this and treating FrameIndex as a private implementation detail.

self,
data=None,
dtype=None,
*,
name=None,
session=None,
linked_frame: Union[
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it an internal only param or part of the public API? If internal, we may want to make it only in a private constructor. If public API, then should update the docs.

Looks like pandas doesn't have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for internal purposes only. Removed from constructor, now directly set the property after initialized.

@@ -454,24 +475,27 @@ def __len__(self):
return self.shape[0]


# Index that mutates the originating dataframe/series
class FrameIndex(Index):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch @GarrettWu.

Given that we say ) -> Index: in the only method that would return such an object and we don't explicitly document FrameIndex, I'm okay overlooking this and treating FrameIndex as a private implementation detail.

):
super().__init__(series_or_dataframe._block)
self._whole_frame = series_or_dataframe
class MultiIndex(Index, vendored_pandas_multindex.MultiIndex):
Copy link
Collaborator

Choose a reason for hiding this comment

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

As much as possible, I'd like our module hierarch to reflect pandas. In pandas, this is defined in pandas/core/indexes/multi.py. Anything under core is considered private-ish, but these paths do leak out in some of the pandas docs.

https://github.com/pandas-dev/pandas/blob/5232bee8df3b57766c44b62152aa3fdd24e40ada/pandas/core/indexes/multi.py#L224

Let's make a bigframes/core/indexes/multi.py file and put this there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@TrevorBergeron TrevorBergeron added the automerge Merge the pull request once unit tests and other checks pass. label Apr 10, 2024
@TrevorBergeron TrevorBergeron merged commit 5d0f149 into main Apr 10, 2024
15 of 16 checks passed
@TrevorBergeron TrevorBergeron deleted the index_subclass branch April 10, 2024 21:40
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants