-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(bigframes): Add numpy ufunc support to col expressions #16554
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |||||||||||||||||||||||||
| import bigframes | ||||||||||||||||||||||||||
| import bigframes.pandas as bpd | ||||||||||||||||||||||||||
| from bigframes.testing.utils import assert_frame_equal, convert_pandas_dtypes | ||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| pytest.importorskip("polars") | ||||||||||||||||||||||||||
| pytest.importorskip("pandas", minversion="3.0.0") | ||||||||||||||||||||||||||
|
|
@@ -246,3 +247,26 @@ def test_col_dt_accessor(scalars_dfs): | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # int64[pyarrow] vs Int64 | ||||||||||||||||||||||||||
| assert_frame_equal(bf_result, pd_result, check_dtype=False) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def test_col_numpy_ufunc(scalars_dfs): | ||||||||||||||||||||||||||
| scalars_df, scalars_pandas_df = scalars_dfs | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| bf_kwargs = { | ||||||||||||||||||||||||||
| "sqrt": np.sqrt(bpd.col("float64_col")), # type: ignore | ||||||||||||||||||||||||||
| "add_const": np.add(bpd.col("float64_col"), 2.4), # type: ignore | ||||||||||||||||||||||||||
| "radd_const": np.add(2.4, bpd.col("float64_col")), # type: ignore | ||||||||||||||||||||||||||
| "add_cols": np.add(bpd.col("float64_col"), bpd.col("int64_col")), # type: ignore | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| pd_kwargs = { | ||||||||||||||||||||||||||
| "sqrt": np.sqrt(pd.col("float64_col")), # type: ignore | ||||||||||||||||||||||||||
| "add_const": np.add(pd.col("float64_col"), 2.4), # type: ignore | ||||||||||||||||||||||||||
| "radd_const": np.add(2.4, pd.col("float64_col")), # type: ignore | ||||||||||||||||||||||||||
| "add_cols": np.add(pd.col("float64_col"), pd.col("int64_col")), # type: ignore | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+261
to
+266
Contributor
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. The
Suggested change
References
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| bf_result = scalars_df.assign(**bf_kwargs).to_pandas() | ||||||||||||||||||||||||||
| pd_result = scalars_pandas_df.assign(**pd_kwargs) # type: ignore | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # int64[pyarrow] vs Int64 | ||||||||||||||||||||||||||
| assert_frame_equal(bf_result, pd_result, check_dtype=False) | ||||||||||||||||||||||||||
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.
Using
__builtins__.stras a type hint is non-standard and potentially fragile. It is recommended to use the built-instrtype directly.References