Skip to content
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

SNOW-1652384: Add series/test_to_list and fix test_to_numpy #2534

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions tests/integ/modin/series/test_to_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#

import datetime
import logging

import numpy as np
import pytest
from numpy.testing import assert_array_equal

import snowflake.snowpark.modin.plugin # noqa: F401
from snowflake.snowpark.modin.plugin.utils.warning_message import WarningMessage
from tests.integ.modin.utils import create_test_series, eval_snowpark_pandas_result
from tests.integ.utils.sql_counter import sql_count_checker


def to_list_comparator(snow, native):
assert isinstance(
native, list
), f"expected native pandas result to be list, instead got {type(native)}"
assert isinstance(
snow, list
), f"expected Snowpark pandas result to be list, instead got {type(snow)}"
# use np testing comparator to handle NaN values
assert_array_equal(snow, native)


@pytest.mark.parametrize(
"data",
[
[1, 2, 3],
["a", "b", "c"],
[1.1, np.NaN],
[1.1, 2.2],
[True, False],
[True, False, None],
[bytes("snow", "utf-8"), bytes("flake", "utf-8")],
[bytes("snow", "utf-8"), bytes("flake", "utf-8"), None],
[datetime.date(2023, 1, 1), datetime.date(2023, 9, 15)],
[datetime.date(2023, 1, 1), datetime.date(2023, 9, 15), None],
["a", 1, "11"], # mixed types
],
)
@sql_count_checker(query_count=1)
def test_to_list(data, caplog):
caplog.clear()
WarningMessage.printed_warnings.clear()
with caplog.at_level(logging.WARNING):
eval_snowpark_pandas_result(
*create_test_series(data),
lambda s: s.to_list(),
comparator=to_list_comparator,
)
assert "The current operation leads to materialization" in caplog.text
5 changes: 2 additions & 3 deletions tests/integ/modin/test_to_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def test_to_numpy_basic(data, pandas_obj, func):
assert_array_equal(df.values, native_df.values)
if pandas_obj == "Series":
with SqlCounter(query_count=1):
# SNOW-1652384 use to_numpy here and test to_list separately
res = df.to_list()
expected_res = native_df.to_list()
res = df.to_numpy()
expected_res = native_df.to_numpy()
for r1, r2 in zip(res, expected_res):
# native pandas series returns a list of pandas Timestamp,
# but Snowpark pandas returns a list of integers in ms.
Expand Down
Loading