Best Python code snippet using pandera_python
utils.py
Source:utils.py  
...19            return True20        except Exception:  # pylint:disable=broad-except21            return False22    return series.map(_coercible)23def numpy_pandas_coerce_failure_cases(24    data_container: Union[PandasObject, np.ndarray], type_: Any25) -> PandasObject:26    """27    Get the failure cases resulting from trying to coerce a pandas/numpy object28    into particular data type.29    """30    # pylint: disable=import-outside-toplevel,cyclic-import31    from pandera import error_formatters32    from pandera.engines import pandas_engine33    data_type = pandas_engine.Engine.dtype(type_)34    if isinstance(data_container, np.ndarray):35        if len(data_container.shape) == 1:36            data_container = pd.Series(data_container)37        elif len(data_container.shape) == 2:...test_engine_utils.py
Source:test_engine_utils.py  
...27        pd.DataFrame({0: [1, 2, 3, 4]}),28        np.array([[1], [2], [3], [4]]),29    ],30)31def test_numpy_pandas_coerce_failure_cases(data_container):32    """33    Test that different data container types can be checked for coerce failure34    cases.35    """36    failure_cases = utils.numpy_pandas_coerce_failure_cases(37        data_container, int38    )39    assert isinstance(failure_cases, pd.DataFrame)40    assert failure_cases.empty41@pytest.mark.parametrize(42    "invalid_data_container, exception_type",43    [44        [1, TypeError],45        [5.1, TypeError],46        ["foobar", TypeError],47        [[1, 2, 3], TypeError],48        [{0: 1}, TypeError],49        # pylint: disable=too-many-function-args50        [np.array([1]).reshape(1, 1, 1), ValueError],51    ],52)53def test_numpy_pandas_coerce_failure_cases_exceptions(54    invalid_data_container, exception_type55):56    """57    Test exceptions of trying to get failure cases for invalid input types.58    """59    error_msg = {60        TypeError: "type of data_container .+ not understood",61        ValueError: "only numpy arrays of 1 or 2 dimensions are supported",62    }[exception_type]63    with pytest.raises(exception_type, match=error_msg):...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
