|
| 1 | +# Licensed to Modin Development Team under one or more contributor license agreements. |
| 2 | +# See the NOTICE file distributed with this work for additional information regarding |
| 3 | +# copyright ownership. The Modin Development Team licenses this file to you under the |
| 4 | +# Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 | +# compliance with the License. You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software distributed under |
| 10 | +# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific language |
| 12 | +# governing permissions and limitations under the License. |
| 13 | + |
| 14 | +# While other modin backends raise a warning when defaulting to pandas, it does not make sense to |
| 15 | +# do so when we're running on the native pandas backend already. These tests ensure such warnings |
| 16 | +# are not raised with the pandas backend. |
| 17 | + |
| 18 | +import numpy as np |
| 19 | +import pandas |
| 20 | +import pytest |
| 21 | + |
| 22 | +import modin.pandas as pd |
| 23 | +from modin.config import Backend |
| 24 | +from modin.tests.pandas.utils import df_equals |
| 25 | + |
| 26 | +pytestmark = [ |
| 27 | + pytest.mark.skipif( |
| 28 | + Backend.get() != "Pandas", |
| 29 | + reason="warnings only suppressed on native pandas backend", |
| 30 | + allow_module_level=True, |
| 31 | + ), |
| 32 | + # Error if a default to pandas warning is detected. |
| 33 | + pytest.mark.filterwarnings("error:is not supported by NativeOnNative:UserWarning"), |
| 34 | +] |
| 35 | + |
| 36 | + |
| 37 | +def test_crosstab_no_warning(): |
| 38 | + # Example from pandas docs |
| 39 | + # https://pandas.pydata.org/docs/reference/api/pandas.crosstab.html |
| 40 | + a = np.array( |
| 41 | + ["foo", "foo", "foo", "foo", "bar", "bar", "bar", "bar", "foo", "foo", "foo"], |
| 42 | + dtype=object, |
| 43 | + ) |
| 44 | + b = np.array( |
| 45 | + ["one", "one", "one", "two", "one", "one", "one", "two", "two", "two", "one"], |
| 46 | + dtype=object, |
| 47 | + ) |
| 48 | + c = np.array( |
| 49 | + [ |
| 50 | + "dull", |
| 51 | + "dull", |
| 52 | + "shiny", |
| 53 | + "dull", |
| 54 | + "dull", |
| 55 | + "shiny", |
| 56 | + "shiny", |
| 57 | + "dull", |
| 58 | + "shiny", |
| 59 | + "shiny", |
| 60 | + "shiny", |
| 61 | + ], |
| 62 | + dtype=object, |
| 63 | + ) |
| 64 | + df_equals( |
| 65 | + pd.crosstab(a, [b, c], rownames=["a"], colnames=["b", "c"]), |
| 66 | + pandas.crosstab(a, [b, c], rownames=["a"], colnames=["b", "c"]), |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +def test_json_normalize_no_warning(): |
| 71 | + # Example from pandas docs |
| 72 | + # https://pandas.pydata.org/docs/reference/api/pandas.json_normalize.html |
| 73 | + data = [ |
| 74 | + {"id": 1, "name": {"first": "Coleen", "last": "Volk"}}, |
| 75 | + {"name": {"given": "Mark", "family": "Regner"}}, |
| 76 | + {"id": 2, "name": "Faye Raker"}, |
| 77 | + ] |
| 78 | + df_equals(pd.json_normalize(data), pandas.json_normalize(data)) |
0 commit comments