Skip to content

Commit 9eca152

Browse files
committed
remove more default to pandas warning calls
1 parent 537ccbf commit 9eca152

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

modin/tests/experimental/test_io_exp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
time_parsing_csv_path,
3030
)
3131
from modin.tests.test_utils import (
32-
warns_that_defaulting_to_pandas,
32+
current_execution_is_native,
3333
warns_that_defaulting_to_pandas_if,
3434
)
3535
from modin.utils import try_cast_to_pandas
@@ -129,7 +129,7 @@ def test_read_csv_empty_frame(self):
129129

130130
def test_read_csv_without_glob(self):
131131
with pytest.raises(FileNotFoundError):
132-
with warns_that_defaulting_to_pandas():
132+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
133133
pd.read_csv_glob(
134134
"s3://dask-data/nyc-taxi/2015/yellow_tripdata_2015-",
135135
storage_options={"anon": True},

modin/tests/interchange/dataframe_protocol/pandas/test_protocol.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from modin.tests.pandas.utils import df_equals, test_data
2121
from modin.tests.test_utils import (
2222
df_or_series_using_native_execution,
23-
warns_that_defaulting_to_pandas,
2423
warns_that_defaulting_to_pandas_if,
2524
)
2625

@@ -66,7 +65,9 @@ def test_categorical_from_dataframe():
6665

6766
def test_from_dataframe_with_empty_dataframe():
6867
modin_df = pd.DataFrame({"foo_col": pd.Series([], dtype="int64")})
69-
with warns_that_defaulting_to_pandas():
68+
with warns_that_defaulting_to_pandas_if(
69+
not df_or_series_using_native_execution(modin_df)
70+
):
7071
eval_df_protocol(modin_df)
7172

7273

modin/tests/pandas/extensions/test_groupby_extensions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
)
2525
from modin.pandas.groupby import DataFrameGroupBy, SeriesGroupBy
2626
from modin.tests.pandas.utils import default_to_pandas_ignore_string, df_equals
27-
from modin.tests.test_utils import warns_that_defaulting_to_pandas
27+
from modin.tests.test_utils import (
28+
current_execution_is_native,
29+
warns_that_defaulting_to_pandas_if,
30+
)
2831

2932

3033
@pytest.mark.parametrize(
@@ -150,10 +153,7 @@ def ngroups(self):
150153
# Check that the accessor doesn't work on the Python_Test backend.
151154
python_test_df = pandas_df.move_to("Python_Test")
152155
groupby = get_groupby(python_test_df)
153-
# groupby.ngroups defaults to pandas at the API layer,
154-
# where it warns that it's doing so, even for dataframes using the
155-
# Pandas backend.
156-
with warns_that_defaulting_to_pandas():
156+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
157157
assert groupby.ngroups == 3
158158

159159
def test_add_ngroups_setter_and_deleter_for_one_backend(
@@ -179,7 +179,7 @@ def _set_ngroups(self, value):
179179

180180
python_test_groupby = get_groupby(python_test_df)
181181

182-
with warns_that_defaulting_to_pandas():
182+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
183183
assert python_test_groupby.ngroups == 3
184184

185185
with pytest.raises(AttributeError):

modin/tests/pandas/test_general.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from modin.tests.test_utils import (
2323
current_execution_is_native,
2424
df_or_series_using_native_execution,
25-
warns_that_defaulting_to_pandas,
2625
warns_that_defaulting_to_pandas_if,
2726
)
2827
from modin.utils import get_current_execution
@@ -276,7 +275,9 @@ def test_merge_asof_suffixes():
276275
right_index=True,
277276
suffixes=(False, False),
278277
)
279-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
278+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
279+
not current_execution_is_native()
280+
):
280281
pd.merge_asof(
281282
modin_left,
282283
modin_right,
@@ -297,57 +298,79 @@ def test_merge_asof_bad_arguments():
297298
pandas.merge_asof(
298299
pandas_left, pandas_right, on="a", by="b", left_by="can't do with by"
299300
)
300-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
301+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
302+
not current_execution_is_native()
303+
):
301304
pd.merge_asof(
302305
modin_left, modin_right, on="a", by="b", left_by="can't do with by"
303306
)
304307
with pytest.raises(ValueError):
305308
pandas.merge_asof(
306309
pandas_left, pandas_right, by="b", on="a", right_by="can't do with by"
307310
)
308-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
311+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
312+
not current_execution_is_native()
313+
):
309314
pd.merge_asof(
310315
modin_left, modin_right, by="b", on="a", right_by="can't do with by"
311316
)
312317

313318
# Can't mix on with left_on/right_on
314319
with pytest.raises(ValueError):
315320
pandas.merge_asof(pandas_left, pandas_right, on="a", left_on="can't do with by")
316-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
321+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
322+
not current_execution_is_native()
323+
):
317324
pd.merge_asof(modin_left, modin_right, on="a", left_on="can't do with by")
318325
with pytest.raises(ValueError):
319326
pandas.merge_asof(
320327
pandas_left, pandas_right, on="a", right_on="can't do with by"
321328
)
322-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
329+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
330+
not current_execution_is_native()
331+
):
323332
pd.merge_asof(modin_left, modin_right, on="a", right_on="can't do with by")
324333

325334
# Can't mix left_index with left_on or on, similarly for right.
326-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
335+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
336+
not current_execution_is_native()
337+
):
327338
pd.merge_asof(modin_left, modin_right, on="a", right_index=True)
328-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
339+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
340+
not current_execution_is_native()
341+
):
329342
pd.merge_asof(
330343
modin_left, modin_right, left_on="a", right_on="a", right_index=True
331344
)
332-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
345+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
346+
not current_execution_is_native()
347+
):
333348
pd.merge_asof(modin_left, modin_right, on="a", left_index=True)
334-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
349+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
350+
not current_execution_is_native()
351+
):
335352
pd.merge_asof(
336353
modin_left, modin_right, left_on="a", right_on="a", left_index=True
337354
)
338355

339356
# Need both left and right
340357
with pytest.raises(Exception): # Pandas bug, didn't validate inputs sufficiently
341358
pandas.merge_asof(pandas_left, pandas_right, left_on="a")
342-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
359+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
360+
not current_execution_is_native()
361+
):
343362
pd.merge_asof(modin_left, modin_right, left_on="a")
344363
with pytest.raises(Exception): # Pandas bug, didn't validate inputs sufficiently
345364
pandas.merge_asof(pandas_left, pandas_right, right_on="a")
346-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
365+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
366+
not current_execution_is_native()
367+
):
347368
pd.merge_asof(modin_left, modin_right, right_on="a")
348369
with pytest.raises(ValueError):
349370
pandas.merge_asof(pandas_left, pandas_right)
350-
with pytest.raises(ValueError), warns_that_defaulting_to_pandas():
371+
with pytest.raises(ValueError), warns_that_defaulting_to_pandas_if(
372+
not current_execution_is_native()
373+
):
351374
pd.merge_asof(modin_left, modin_right)
352375

353376

@@ -386,7 +409,7 @@ def test_merge_asof_merge_options():
386409
pandas_quotes, pandas_trades = to_pandas(modin_quotes), to_pandas(modin_trades)
387410

388411
# left_by + right_by
389-
with warns_that_defaulting_to_pandas():
412+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
390413
modin_result = pd.merge_asof(
391414
modin_quotes,
392415
modin_trades,
@@ -408,7 +431,7 @@ def test_merge_asof_merge_options():
408431
# Just by:
409432
pandas_trades["ticker"] = pandas_trades["ticker2"]
410433
modin_trades["ticker"] = modin_trades["ticker2"]
411-
with warns_that_defaulting_to_pandas():
434+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
412435
modin_result = pd.merge_asof(
413436
modin_quotes,
414437
modin_trades,
@@ -426,7 +449,7 @@ def test_merge_asof_merge_options():
426449
)
427450

428451
# Tolerance
429-
with warns_that_defaulting_to_pandas():
452+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
430453
modin_result = pd.merge_asof(
431454
modin_quotes,
432455
modin_trades,
@@ -446,7 +469,7 @@ def test_merge_asof_merge_options():
446469
)
447470

448471
# Direction
449-
with warns_that_defaulting_to_pandas():
472+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
450473
modin_result = pd.merge_asof(
451474
modin_quotes,
452475
modin_trades,
@@ -466,7 +489,7 @@ def test_merge_asof_merge_options():
466489
)
467490

468491
# Allow exact matches
469-
with warns_that_defaulting_to_pandas():
492+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
470493
modin_result = pd.merge_asof(
471494
modin_quotes,
472495
modin_trades,
@@ -643,7 +666,7 @@ def test_value_counts(normalize, bins, dropna):
643666
)
644667
df_equals(modin_result, pandas_result)
645668

646-
with warns_that_defaulting_to_pandas():
669+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
647670
modin_result = sort_index_for_equal_values(
648671
pd.value_counts(values, bins=bins, ascending=False), False
649672
)
@@ -720,7 +743,7 @@ def test_qcut(retbins):
720743
modin_series = pd.Series(range(10))
721744
pandas_result = pandas.qcut(pandas_series, 4, retbins=retbins)
722745
# NOTE that qcut() defaults to pandas at the API layer.
723-
with warns_that_defaulting_to_pandas():
746+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
724747
modin_result = pd.qcut(modin_series, 4, retbins=retbins)
725748
if retbins:
726749
df_equals(modin_result[0], pandas_result[0])
@@ -812,7 +835,7 @@ def test_cut_fallback():
812835
pandas_result = pandas.cut(range(5), 4)
813836
# note that we default to pandas at the API layer here, so we warn
814837
# regardless of whether we are on native execution.
815-
with warns_that_defaulting_to_pandas():
838+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
816839
modin_result = pd.cut(range(5), 4)
817840
df_equals(modin_result, pandas_result)
818841

@@ -930,7 +953,7 @@ def test_default_to_pandas_warning_message(func, regex):
930953
def test_empty_dataframe():
931954
df = pd.DataFrame(columns=["a", "b"])
932955
# NOTE that we default to pandas at the API layer.
933-
with warns_that_defaulting_to_pandas():
956+
with warns_that_defaulting_to_pandas_if(not current_execution_is_native()):
934957
df[(df.a == 1) & (df.b == 2)]
935958

936959

0 commit comments

Comments
 (0)