{"record":{"id":"63baf886f1a2fbda","repo":"pandas-dev/pandas","slug":"cls-name-expected-type-cls-found-type-right","errorCode":null,"errorMessage":"{cls_name} Expected type {cls}, found {type(right)} 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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_testing/asserters.py#L167-L203","documentation":"Raised by _check_isinstance (asserters.py:184-187) when the 'right' argument to a pandas.testing assertion function is not an instance of the expected class. Symmetric twin of the left-side check; same cause and audience — a test-author type mismatch on the second (usually 'expected') operand.","triggerScenarios":"Calling assert_series_equal(pd.Series([...]), np.array([...])) where right is a numpy array; assert_index_equal(index, list_of_labels); assert_frame_equal(df, dict_of_columns). Any pandas.testing assert_*_equal with a right operand of the wrong type.","commonSituations":"Building the expected fixture as a dict/list/array and forgetting to wrap it; mock objects or third-party types substituted for the real pandas object; copy-paste of a test that compared lists now compared against Series.","solutions":["Wrap the right argument in the expected constructor: pd.Series(right_list), pd.Index(right_array), pd.DataFrame(right_dict).","Pick the assertion function matching the right operand's type.","Read the 'found <type>' portion of the message to identify the mismatched object."],"exampleFix":"# before\nassert_series_equal(pd.Series([1, 2, 3]), [1, 2, 3])\n\n# after\nassert_series_equal(pd.Series([1, 2, 3]), pd.Series([1, 2, 3]))","handlingStrategy":"type-guard","validationCode":"import pandas as pd\nfrom pandas.testing import assert_series_equal\nright = build_expected()\nif not isinstance(right, pd.Series):\n    right = pd.Series(right)\nassert_series_equal(left, right)","typeGuard":"import pandas as pd\n\ndef is_series(obj: object) -> bool:\n    return isinstance(obj, pd.Series)","tryCatchPattern":null,"preventionTips":["Build expected fixtures with pd.Series/pd.Index/pd.DataFrame, not raw lists.","Match the assertion helper to the operand type.","Check isinstance on the right operand when data comes from external sources."],"tags":["testing","assertion","type-check","assert-series-equal"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}