-
Notifications
You must be signed in to change notification settings - Fork 48
feat: define list accessor for bigframes Series #946
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
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
28279bb
feat: define list accessor for bigframes Series
sycai 404e940
Add doc for list accessor
sycai 003247a
Fix bug in docstring and inheritance
sycai 098b620
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 883eed1
Skip test if Pandas version is too old
sycai a9d3a92
Merge branch 'main' into b361406184
sycai 72199d8
Fix docstring format, and provide notebook examples.
sycai f17d4b3
Merge branch 'main' into b361406184
sycai 850a42e
Use func link under see also
sycai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import bigframes.operations as ops | ||
|
||
|
||
def convert_index(key: int) -> ops.ArrayIndexOp: | ||
if key < 0: | ||
raise NotImplementedError("Negative indexing is not supported.") | ||
return ops.ArrayIndexOp(index=key) | ||
|
||
|
||
def convert_slice(key: slice) -> ops.ArraySliceOp: | ||
if key.step is not None and key.step != 1: | ||
raise NotImplementedError(f"Only a step of 1 is allowed, got {key.step}") | ||
|
||
if (key.start is not None and key.start < 0) or ( | ||
key.stop is not None and key.stop < 0 | ||
): | ||
raise NotImplementedError("Slicing with negative numbers is not allowed.") | ||
|
||
return ops.ArraySliceOp( | ||
start=key.start if key.start is not None else 0, | ||
stop=key.stop, | ||
step=key.step, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
import inspect | ||
from typing import Union | ||
|
||
import bigframes_vendored.pandas.core.arrays.arrow.accessors as vendoracessors | ||
|
||
from bigframes.core import log_adapter | ||
import bigframes.operations as ops | ||
from bigframes.operations._op_converters import convert_index, convert_slice | ||
import bigframes.operations.base | ||
import bigframes.series as series | ||
|
||
|
||
@log_adapter.class_logger | ||
class ListAccessor( | ||
bigframes.operations.base.SeriesMethods, vendoracessors.ListAccessor | ||
): | ||
__doc__ = vendoracessors.ListAccessor.__doc__ | ||
|
||
def len(self): | ||
return self._apply_unary_op(ops.len_op) | ||
|
||
def __getitem__(self, key: Union[int, slice]) -> series.Series: | ||
if isinstance(key, int): | ||
return self._apply_unary_op(convert_index(key)) | ||
elif isinstance(key, slice): | ||
return self._apply_unary_op(convert_slice(key)) | ||
else: | ||
raise ValueError(f"key must be an int or slice, got {type(key).__name__}") | ||
|
||
__getitem__.__doc__ = inspect.getdoc(vendoracessors.ListAccessor.__getitem__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please add the doctest on https://github.com/googleapis/python-bigquery-dataframes/blob/main/third_party/bigframes_vendored/pandas/core/series.py
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.
Also, please add the new accessor to docs/reference/bigframes.pandas/series.rst
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.
Change updated. PTAL!