Skip to content

Commit c331dfe

Browse files
feat: Add __abs__ to dataframe (#2186)
1 parent cd87ce0 commit c331dfe

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

bigframes/dataframe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,11 @@ def __pos__(self) -> DataFrame:
13061306
def __neg__(self) -> DataFrame:
13071307
return self._apply_unary_op(ops.neg_op)
13081308

1309+
def __abs__(self) -> DataFrame:
1310+
return self._apply_unary_op(ops.abs_op)
1311+
1312+
__abs__.__doc__ = abs.__doc__
1313+
13091314
def align(
13101315
self,
13111316
other: typing.Union[DataFrame, bigframes.series.Series],

bigframes/series.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,8 @@ def update(self, other: Union[Series, Sequence, Mapping]) -> None:
13641364
def __abs__(self) -> Series:
13651365
return self.abs()
13661366

1367+
__abs__.__doc__ = inspect.getdoc(vendored_pandas_series.Series.abs)
1368+
13671369
def abs(self) -> Series:
13681370
return self._apply_unary_op(ops.abs_op)
13691371

tests/system/small/test_dataframe.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,16 @@ def test_df_neg(scalars_dfs):
24602460
assert_pandas_df_equal(pd_result, bf_result)
24612461

24622462

2463+
def test_df__abs__(scalars_dfs):
2464+
scalars_df, scalars_pandas_df = scalars_dfs
2465+
bf_result = (
2466+
abs(scalars_df[["int64_col", "numeric_col", "float64_col"]])
2467+
).to_pandas()
2468+
pd_result = abs(scalars_pandas_df[["int64_col", "numeric_col", "float64_col"]])
2469+
2470+
assert_pandas_df_equal(pd_result, bf_result)
2471+
2472+
24632473
def test_df_invert(scalars_dfs):
24642474
scalars_df, scalars_pandas_df = scalars_dfs
24652475
columns = ["int64_col", "bool_col"]

0 commit comments

Comments
 (0)