{"record":{"id":"448b2b376af40ab4","repo":"pandas-dev/pandas","slug":"cls-name-expected-type-cls-found-type-left","errorCode":null,"errorMessage":"{cls_name} Expected type {cls}, found {type(left)} instead","messagePattern":"(.+?) Expected type (.+?), found (.+?) instead","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"pandas/_testing/asserters.py","lineNumber":185,"sourceCode":"\n    Parameters\n    ----------\n    left : The first object being compared.\n    right : The second object being compared.\n    cls : The class type to check against.\n\n    Raises\n    ------\n    AssertionError : Either `left` or `right` is not an instance of `cls`.\n    \"\"\"\n    cls_name = cls.__name__\n\n    if not isinstance(left, cls):\n        raise AssertionError(\n            f\"{cls_name} Expected type {cls}, found {type(left)} instead\"\n        )\n    if not isinstance(right, cls):\n        raise AssertionError(\n            f\"{cls_name} Expected type {cls}, found {type(right)} instead\"\n        )\n\n\ndef assert_dict_equal(left: dict, right: dict, compare_keys: bool = True) -> None:\n    _check_isinstance(left, right, dict)\n    _testing.assert_dict_equal(left, right, compare_keys=compare_keys)\n\n\n@set_module(\"pandas.testing\")\ndef assert_index_equal(\n    left: Index,\n    right: Index,\n    exact: bool | str | lib.NoDefault = lib.no_default,\n    check_names: bool = True,\n    check_exact: bool = True,\n    check_categorical: bool = True,\n    check_order: bool = True,","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_testing/asserters.py#L167-L203","documentation":"Raised by `_check_isinstance`, a guard at the entry of pandas testing asserters (`assert_index_equal`, `assert_series_equal`, `assert_frame_equal`, `assert_dict_equal`, etc.). It fires when `left` or `right` is not an instance of the expected class `cls`, signaling the test is comparing mismatched object types rather than values. This is a programming-error-class failure in test code, not data.","triggerScenarios":"Calling `pd.testing.assert_series_equal(df, df2)` (passing DataFrames to a Series asserter); `assert_index_equal(df.index.values, df2.index.values)` (passing numpy arrays instead of Index); `assert_dict_equal(list_a, dict_b)`.","commonSituations":"Test refactors where an object type changed; copy-pasting an assertion from a Series test into a DataFrame test without changing the asserter; passing `.values`/`.to_numpy()` where the Index/Series object is required.","solutions":["Match the asserter to the object: assert_frame_equal for DataFrames, assert_series_equal for Series, assert_index_equal for Index.","Drop `.values`/`.to_numpy()` so you pass the pandas object, not the underlying ndarray.","Read the message's `{cls}` to pick the correct asserter function name."],"exampleFix":"// before\npd.testing.assert_series_equal(df_a, df_b)\n\n// after\npd.testing.assert_frame_equal(df_a, df_b)","handlingStrategy":"type-guard","validationCode":"import pandas as pd\nassert isinstance(left, pd.Series) and isinstance(right, pd.Series)","typeGuard":"import pandas as pd\ndef both_are(cls, a, b) -> bool:\n    return isinstance(a, cls) and isinstance(b, cls)","tryCatchPattern":null,"preventionTips":["Match the asserter function to the object type.","Don't pass .values/.to_numpy() to Index/Series asserters."],"tags":["testing","type-mismatch","assertions"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}