-
Notifications
You must be signed in to change notification settings - Fork 48
refactor: Decorate api methods that require total ordering #802
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
844f21c
to
6ef878d
Compare
bigframes/core/indexes/base.py
Outdated
@@ -424,6 +433,8 @@ def dropna(self, how: typing.Literal["all", "any"] = "any") -> Index: | |||
return Index(result) | |||
|
|||
def drop_duplicates(self, *, keep: str = "first") -> Index: | |||
if keep is not False: | |||
enforce_ordered(self, "duplicated") |
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.
Is this a typo? I assume it should reflect the public API name used, right?
enforce_ordered(self, "duplicated") | |
enforce_ordered(self, "drop_duplicates") |
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.
fixed
bigframes/core/indexes/base.py
Outdated
@@ -30,6 +30,7 @@ | |||
import bigframes.core.expression as ex | |||
import bigframes.core.ordering as order | |||
import bigframes.core.utils as utils | |||
from bigframes.core.validate import enforce_ordered, requires_strict_ordering |
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.
Import modules, not methods.
https://google.github.io/styleguide/pyguide.html#22-imports
There are only a few exceptions: https://google.github.io/styleguide/pyguide.html#2241-exemptions
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.
done
bigframes/core/window_spec.py
Outdated
|
||
@property | ||
def row_bounded(self): | ||
# relevant for determining if window requires total ordering for determinism. |
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: This could be transformed into a docstring. I like that you shared the "why" but I'd also like a little more explanation on what row_bounded means.
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.
changed to docstring
bigframes/dataframe.py
Outdated
@@ -61,6 +61,7 @@ | |||
import bigframes.core.indexes as indexes | |||
import bigframes.core.ordering as order | |||
import bigframes.core.utils as utils | |||
from bigframes.core.validate import enforce_ordered, requires_strict_ordering |
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.
Import packages not methods.
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.
done
bigframes/core/groupby/__init__.py
Outdated
@@ -27,6 +27,7 @@ | |||
import bigframes.core.blocks as blocks | |||
import bigframes.core.ordering as order | |||
import bigframes.core.utils as utils | |||
from bigframes.core.validate import requires_strict_ordering |
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.
Import packages not methods.
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.
done
bigframes/core/validate.py
Outdated
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: I'd prefer a noun for a package name. How about validations.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.
done
bigframes/operations/aggregations.py
Outdated
@@ -42,6 +42,11 @@ def uses_total_row_ordering(self): | |||
def can_order_by(self): | |||
return False | |||
|
|||
@property | |||
def order_independent(self): | |||
"""Whether the output of the operator depends on the ordering of input rows. Navigation functions are a notable case.""" |
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.
Let's keep the title line short.
"""Whether the output of the operator depends on the ordering of input rows. Navigation functions are a notable case.""" | |
"""True if the output of the operator depends on the ordering of input rows. | |
Navigation functions are a notable case. | |
""" |
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.
done
bigframes/operations/aggregations.py
Outdated
@@ -78,6 +83,11 @@ def name(self) -> str: | |||
def arguments(self) -> int: | |||
... | |||
|
|||
@property | |||
def order_independent(self): | |||
# Almost all aggregation functions are order independent, excepting array and string agg |
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.
Let's make this a docstring too.
# Almost all aggregation functions are order independent, excepting array and string agg | |
"""True if results don't depend on the order of the input. | |
Almost all aggregation functions are order independent, excepting ``array_agg`` and ``string_agg``. | |
""" |
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.
done
bigframes/series.py
Outdated
@@ -43,6 +43,7 @@ | |||
import bigframes.core.ordering as order | |||
import bigframes.core.scalar as scalars | |||
import bigframes.core.utils as utils | |||
from bigframes.core.validate import enforce_ordered, requires_strict_ordering |
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.
import package
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.
done
tests/system/small/test_unordered.py
Outdated
pytest.param( | ||
lambda x: x.cumsum(), | ||
id="cumsum", | ||
marks=pytest.mark.xfail(raises=bigframes.exceptions.OrderRequiredError), |
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.
Since all of these tests fail with the same exception, prefer with pytest.raises(...)
in the test function body. Ideally we check for the function name in the error message with match=
as well.
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.
done
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:
Fixes #<issue_number_goes_here> 🦕