-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3281a0f
commit 10bd8d9
Showing
2 changed files
with
80 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,58 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
from tests.utils import convert_series_to_pandas_numpy | ||
from tests.utils import integer_series_1 | ||
from tests.utils import convert_dataframe_to_pandas_numpy | ||
from tests.utils import integer_dataframe_1 | ||
from tests.utils import interchange_to_pandas | ||
|
||
if TYPE_CHECKING: | ||
import pytest | ||
|
||
|
||
def test_float_powers_column(library: str, request: pytest.FixtureRequest) -> None: | ||
ser = integer_series_1(library, request) | ||
other = integer_series_1(library, request) * 1.0 | ||
result = ser.__pow__(other) | ||
namespace = ser.__column_namespace__() | ||
result_pd = pd.api.interchange.from_dataframe( | ||
namespace.dataframe_from_dict({"result": (result).rename("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) | ||
df = integer_dataframe_1(library) | ||
ser = df.get_column_by_name("a") | ||
other = df.get_column_by_name("b") * 1.0 | ||
result = df.insert(0, "result", ser.__pow__(other)) | ||
result_pd = interchange_to_pandas(result, library) | ||
expected = pd.DataFrame( | ||
{"result": [1.0, 32.0, 729.0], "a": [1, 2, 3], "b": [4, 5, 6]} | ||
) | ||
result_pd = convert_dataframe_to_pandas_numpy(result_pd) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
|
||
|
||
def test_float_powers_scalar_column(library: str, request: pytest.FixtureRequest) -> None: | ||
ser = integer_series_1(library, request) | ||
df = integer_dataframe_1(library) | ||
ser = df.get_column_by_name("a") | ||
other = 1.0 | ||
result = ser.__pow__(other) | ||
namespace = ser.__column_namespace__() | ||
result_pd = pd.api.interchange.from_dataframe( | ||
namespace.dataframe_from_dict({"result": (result).rename("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, request: pytest.FixtureRequest) -> None: | ||
ser = integer_series_1(library, request) | ||
other = integer_series_1(library, request) * -1 | ||
with pytest.raises(ValueError): | ||
ser.__pow__(-1) | ||
with pytest.raises(ValueError): | ||
ser.__pow__(other) | ||
result = df.insert(0, "result", ser.__pow__(other)) | ||
result_pd = interchange_to_pandas(result, library) | ||
expected = pd.DataFrame({"result": [1.0, 2.0, 3.0], "a": [1, 2, 3], "b": [4, 5, 6]}) | ||
result_pd = convert_dataframe_to_pandas_numpy(result_pd) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
|
||
|
||
def test_int_powers_column(library: str, request: pytest.FixtureRequest) -> None: | ||
df = integer_dataframe_1(library) | ||
ser = df.get_column_by_name("a") | ||
other = df.get_column_by_name("b") * 1 | ||
result = df.insert(0, "result", ser.__pow__(other)) | ||
result_pd = interchange_to_pandas(result, library) | ||
expected = pd.DataFrame({"result": [1, 32, 729], "a": [1, 2, 3], "b": [4, 5, 6]}) | ||
result_pd = convert_dataframe_to_pandas_numpy(result_pd) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
|
||
|
||
def test_int_powers_scalar_column(library: str, request: pytest.FixtureRequest) -> None: | ||
df = integer_dataframe_1(library) | ||
ser = df.get_column_by_name("a") | ||
other = 1 | ||
result = df.insert(0, "result", ser.__pow__(other)) | ||
result_pd = interchange_to_pandas(result, library) | ||
expected = pd.DataFrame({"result": [1, 2, 3], "a": [1, 2, 3], "b": [4, 5, 6]}) | ||
result_pd = convert_dataframe_to_pandas_numpy(result_pd) | ||
pd.testing.assert_frame_equal(result_pd, expected) |