Skip to content

Commit 0993c21

Browse files
style
1 parent 48f7979 commit 0993c21

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

packages/bigframes/bigframes/core/col.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,8 @@ def dt(self) -> datetimes.DatetimeSimpleMethods:
161161

162162
return datetimes.DatetimeSimpleMethods(self)
163163

164-
@property
165-
def str(self) -> strings.StringMethods:
166-
import bigframes.operations.strings as strings
167-
168-
return strings.StringMethods(self)
169-
170164
def __array_ufunc__(
171-
self, ufunc: numpy.ufunc, method: __builtins__.str, *inputs, **kwargs
165+
self, ufunc: numpy.ufunc, method: str, *inputs, **kwargs
172166
) -> Expression:
173167
"""Used to support numpy ufuncs.
174168
See: https://numpy.org/doc/stable/reference/ufuncs.html
@@ -189,6 +183,13 @@ def __array_ufunc__(
189183

190184
return NotImplemented
191185

186+
# keep this last as str declaration can shadow builtins.str
187+
@property
188+
def str(self) -> strings.StringMethods:
189+
import bigframes.operations.strings as strings
190+
191+
return strings.StringMethods(self)
192+
192193

193194
def _as_bf_expr(arg: Any) -> bf_expression.Expression:
194195
if isinstance(arg, Expression):

packages/bigframes/tests/unit/test_col.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,18 @@ def test_col_dt_accessor(scalars_dfs):
252252
def test_col_numpy_ufunc(scalars_dfs):
253253
scalars_df, scalars_pandas_df = scalars_dfs
254254

255-
bf_kwargs = {
256-
"sqrt": np.sqrt(bpd.col("float64_col")), # type: ignore
257-
"add_const": np.add(bpd.col("float64_col"), 2.4), # type: ignore
258-
"radd_const": np.add(2.4, bpd.col("float64_col")), # type: ignore
259-
"add_cols": np.add(bpd.col("float64_col"), bpd.col("int64_col")), # type: ignore
260-
}
261-
pd_kwargs = {
262-
"sqrt": np.sqrt(pd.col("float64_col")), # type: ignore
263-
"add_const": np.add(pd.col("float64_col"), 2.4), # type: ignore
264-
"radd_const": np.add(2.4, pd.col("float64_col")), # type: ignore
265-
"add_cols": np.add(pd.col("float64_col"), pd.col("int64_col")), # type: ignore
266-
}
267-
268-
bf_result = scalars_df.assign(**bf_kwargs).to_pandas()
269-
pd_result = scalars_pandas_df.assign(**pd_kwargs) # type: ignore
255+
bf_result = scalars_df.assign(
256+
sqrt=np.sqrt(bpd.col("float64_col")), # type: ignore
257+
add_const=np.add(bpd.col("float64_col"), 2.4), # type: ignore
258+
radd_const=np.add(2.4, bpd.col("float64_col")), # type: ignore
259+
add_cols=np.add(bpd.col("float64_col"), bpd.col("int64_col")), # type: ignore
260+
).to_pandas()
261+
pd_result = scalars_pandas_df.assign(
262+
sqrt=np.sqrt(pd.col("float64_col")), # type: ignore
263+
add_const=np.add(pd.col("float64_col"), 2.4), # type: ignore
264+
radd_const=np.add(2.4, pd.col("float64_col")), # type: ignore
265+
add_cols=np.add(pd.col("float64_col"), pd.col("int64_col")), # type: ignore
266+
)
270267

271268
# int64[pyarrow] vs Int64
272269
assert_frame_equal(bf_result, pd_result, check_dtype=False)

0 commit comments

Comments
 (0)