Skip to content

Commit

Permalink
back to 100% cov
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jul 24, 2023
1 parent fe41815 commit 7081709
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
6 changes: 2 additions & 4 deletions dataframe_api_compat/polars_standard/polars_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __pow__(self, other: Column[DType] | Any) -> PolarsColumn[Any]:
ret = ret.cast(original_type)
else:
ret = self.column.pow(other) # type: ignore[arg-type]
if _is_integer_dtype(original_type) and isinstance(other, (int, float)):
if _is_integer_dtype(original_type) and isinstance(other, int):
if other < 0:
raise ValueError("Cannot raise integer to negative power")
ret = ret.cast(original_type)
Expand Down Expand Up @@ -468,9 +468,7 @@ def __pow__(self, other: DataFrame | Any) -> PolarsDataFrame:
]
)
for column in self.dataframe.columns:
if _is_integer_dtype(original_type[column]) and isinstance(
other, (int, float)
):
if _is_integer_dtype(original_type[column]) and isinstance(other, int):
if other < 0:
raise ValueError("Cannot raise integer to negative power")
ret = ret.with_columns(pl.col(column).cast(original_type[column]))
Expand Down
36 changes: 36 additions & 0 deletions test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,42 @@ def test_float_powers(library: str):
pd.testing.assert_frame_equal(result_pd, expected)


def test_float_scalar_powers(library: str):
df = integer_dataframe_1(library)
other = 1.0
result = df.__pow__(other)
result_pd = pd.api.interchange.from_dataframe(result.dataframe)
expected = pd.DataFrame({"a": [1.0, 2.0, 3.0], "b": [4.0, 5.0, 6.0]})
result_pd = convert_dataframe_to_pandas_numpy(result_pd)
pd.testing.assert_frame_equal(result_pd, expected)


def test_float_powers_column(library: str):
ser = integer_series_1(library)
other = integer_series_1(library) * 1.0
result = ser.__pow__(other)
namespace = ser.__column_namespace__()
result_pd = pd.api.interchange.from_dataframe(
namespace.dataframe_from_dict({"result": result}).dataframe
)["result"]
expected = pd.Series([1.0, 4.0, 27.0], name="result")
result_pd = convert_series_to_pandas_numpy(result_pd)
pd.testing.assert_series_equal(result_pd, expected)


def test_float_powers_scalar_column(library: str):
ser = integer_series_1(library)
other = 1.0
result = ser.__pow__(other)
namespace = ser.__column_namespace__()
result_pd = pd.api.interchange.from_dataframe(
namespace.dataframe_from_dict({"result": result}).dataframe
)["result"]
expected = pd.Series([1.0, 2.0, 3.0], name="result")
result_pd = convert_series_to_pandas_numpy(result_pd)
pd.testing.assert_series_equal(result_pd, expected)


def test_negative_powers_column(library: str):
ser = integer_series_1(library)
other = integer_series_1(library) * -1
Expand Down

0 comments on commit 7081709

Please sign in to comment.