-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add functions to compare Column objects with iterable references and to compare DataFrame objects with mapping references #66
Changes from all commits
d18b9b1
7708bfb
05171fc
f0005d8
65c1f66
efdf097
1ed8fbf
1658fa8
f64ee52
90467c3
01fa14d
a4c4aee
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 |
---|---|---|
|
@@ -35,6 +35,8 @@ | |
"UInt16": "uint16", | ||
"UInt8": "uint8", | ||
"boolean": "bool", | ||
"Float64": "float64", | ||
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. I also discovered by accident, it seems that the float type was missing, but if it was done on purpose, I can try to redo it. 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. i probably just forgot it - let's add float32 too? 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. added |
||
"Float32": "float32", | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,9 @@ ignore = [ | |
[tool.ruff.isort] | ||
force-single-line = true | ||
|
||
[tool.black] | ||
line-length = 90 | ||
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. To sync with |
||
|
||
[tool.pytest.ini_options] | ||
filterwarnings = [ | ||
"error", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
import pandas as pd | ||
|
||
from tests.utils import bool_dataframe_1 | ||
from tests.utils import interchange_to_pandas | ||
from tests.utils import compare_column_with_reference | ||
|
||
|
||
def test_column_and(library: str) -> None: | ||
df = bool_dataframe_1(library, api_version="2023.09-beta") | ||
ns = df.__dataframe_namespace__() | ||
ser = df.col("a") | ||
other = df.col("b") | ||
result = df.assign((ser & other).rename("result")) | ||
result_pd = interchange_to_pandas(result)["result"] | ||
expected = pd.Series([True, True, False], name="result") | ||
pd.testing.assert_series_equal(result_pd, expected) | ||
expected = [True, True, False] | ||
compare_column_with_reference(result.col("result"), expected, dtype=ns.Bool) | ||
|
||
|
||
def test_column_or(library: str) -> None: | ||
df = bool_dataframe_1(library) | ||
ns = df.__dataframe_namespace__() | ||
ser = df.col("a") | ||
other = df.col("b") | ||
result = df.assign((ser | other).rename("result")) | ||
result_pd = interchange_to_pandas(result)["result"] | ||
expected = pd.Series([True, True, True], name="result") | ||
pd.testing.assert_series_equal(result_pd, expected) | ||
expected = [True, True, True] | ||
compare_column_with_reference(result.col("result"), expected, dtype=ns.Bool) | ||
|
||
|
||
def test_column_and_with_scalar(library: str) -> None: | ||
df = bool_dataframe_1(library) | ||
ns = df.__dataframe_namespace__() | ||
ser = df.col("a") | ||
other = True | ||
result = df.assign((other & ser).rename("result")) | ||
result_pd = interchange_to_pandas(result)["result"] | ||
expected = pd.Series([True, True, False], name="result") | ||
pd.testing.assert_series_equal(result_pd, expected) | ||
expected = [True, True, False] | ||
compare_column_with_reference(result.col("result"), expected, dtype=ns.Bool) | ||
|
||
|
||
def test_column_or_with_scalar(library: str) -> None: | ||
df = bool_dataframe_1(library) | ||
ns = df.__dataframe_namespace__() | ||
ser = df.col("a") | ||
other = True | ||
result = df.assign((other | ser).rename("result")) | ||
result_pd = interchange_to_pandas(result)["result"] | ||
expected = pd.Series([True, True, True], name="result") | ||
pd.testing.assert_series_equal(result_pd, expected) | ||
expected = [True, True, True] | ||
compare_column_with_reference(result.col("result"), expected, dtype=ns.Bool) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import pandas as pd | ||
|
||
from tests.utils import compare_dataframe_with_reference | ||
from tests.utils import integer_dataframe_1 | ||
from tests.utils import interchange_to_pandas | ||
|
||
|
||
def test_cast_integers(library: str) -> None: | ||
df = integer_dataframe_1(library) | ||
pdx = df.__dataframe_namespace__() | ||
result = df.assign(df.col("a").cast(pdx.Int32())) | ||
expected = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}).astype( | ||
{"a": "int32", "b": "int64"}, | ||
) | ||
result_pd = interchange_to_pandas(result) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
ns = df.__dataframe_namespace__() | ||
result = df.assign(df.col("a").cast(ns.Int32())) | ||
expected = {"a": [1, 2, 3], "b": [4, 5, 6]} | ||
expected_dtype = {"a": ns.Int32, "b": ns.Int64} | ||
compare_dataframe_with_reference(result, expected, expected_dtype) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,42 @@ | ||
from __future__ import annotations | ||
|
||
import pandas as pd | ||
|
||
from tests.utils import compare_dataframe_with_reference | ||
from tests.utils import integer_dataframe_6 | ||
from tests.utils import interchange_to_pandas | ||
|
||
|
||
def test_expression_sorted_indices_ascending(library: str) -> None: | ||
df = integer_dataframe_6(library) | ||
df.__dataframe_namespace__() | ||
ns = df.__dataframe_namespace__() | ||
col = df.col | ||
sorted_indices = col("b").sorted_indices() | ||
result = df.take(sorted_indices) | ||
result_pd = interchange_to_pandas(result) | ||
expected = pd.DataFrame( | ||
{ | ||
"a": [2, 2, 1, 1, 1], | ||
"b": [1, 2, 3, 4, 4], | ||
}, | ||
) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
expected = {"a": [2, 2, 1, 1, 1], "b": [1, 2, 3, 4, 4]} | ||
compare_dataframe_with_reference(result, expected, dtype=ns.Int64) | ||
|
||
|
||
def test_expression_sorted_indices_descending(library: str) -> None: | ||
df = integer_dataframe_6(library) | ||
df.__dataframe_namespace__() | ||
ns = df.__dataframe_namespace__() | ||
col = df.col | ||
sorted_indices = col("b").sorted_indices(ascending=False) | ||
result = df.take(sorted_indices) | ||
result_pd = interchange_to_pandas(result) | ||
expected = pd.DataFrame( | ||
{ | ||
"a": [1, 1, 1, 2, 2], | ||
"b": [4, 4, 3, 2, 1], | ||
}, | ||
) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
expected = {"a": [1, 1, 1, 2, 2], "b": [4, 4, 3, 2, 1]} | ||
compare_dataframe_with_reference(result, expected, dtype=ns.Int64) | ||
|
||
|
||
def test_column_sorted_indices_ascending(library: str) -> None: | ||
df = integer_dataframe_6(library).persist() | ||
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. I deleted |
||
df = integer_dataframe_6(library) | ||
ns = df.__dataframe_namespace__() | ||
sorted_indices = df.col("b").sorted_indices() | ||
result = df.take(sorted_indices) | ||
result_pd = interchange_to_pandas(result) | ||
expected = pd.DataFrame( | ||
{ | ||
"a": [2, 2, 1, 1, 1], | ||
"b": [1, 2, 3, 4, 4], | ||
}, | ||
) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
expected = {"a": [2, 2, 1, 1, 1], "b": [1, 2, 3, 4, 4]} | ||
compare_dataframe_with_reference(result, expected, dtype=ns.Int64) | ||
|
||
|
||
def test_column_sorted_indices_descending(library: str) -> None: | ||
df = integer_dataframe_6(library).persist() | ||
df = integer_dataframe_6(library) | ||
ns = df.__dataframe_namespace__() | ||
sorted_indices = df.col("b").sorted_indices(ascending=False) | ||
result = df.take(sorted_indices) | ||
result_pd = interchange_to_pandas(result) | ||
expected = pd.DataFrame( | ||
{ | ||
"a": [1, 1, 1, 2, 2], | ||
"b": [4, 4, 3, 2, 1], | ||
}, | ||
) | ||
pd.testing.assert_frame_equal(result_pd, expected) | ||
expected = {"a": [1, 1, 1, 2, 2], "b": [4, 4, 3, 2, 1]} | ||
compare_dataframe_with_reference(result, expected, dtype=ns.Int64) |
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.
I discovered it by accident while experimenting. It is possible that this is no longer necessary for the current changes.