{"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":181,"sourceCode":"    \"\"\"\n    Helper method for our assert_* methods that ensures that\n    the two objects being compared have the right type before\n    proceeding with the comparison.\n\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,","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_testing/asserters.py#L163-L199","documentation":"Raised by _check_isinstance (asserters.py:162-187), the type-guard used at the top of pandas testing assertion functions (assert_index_equal, assert_series_equal, assert_frame_equal, assert_dict_equal, assert_numpy_array_equal, etc.). It raises AssertionError when the 'left' argument is not an instance of the expected class. This is a test-author error, not a data error.","triggerScenarios":"Calling assert_series_equal(list_of_values, series) where left is a Python list instead of a pd.Series; calling assert_index_equal on a plain array; passing a DataFrame where a Series is expected. The function is in pandas.testing and pandas._testing.","commonSituations":"Test helpers that build expected values as lists/dicts and forget to wrap them in the pandas constructor; refactoring a test and changing the object type on one side; comparing a numpy array with assert_numpy_array_equal but passing a list.","solutions":["Wrap the left argument in the expected constructor, e.g. pd.Series(left_list) or pd.Index(left_array).","Use the matching assert function for the actual types (assert_frame_equal for DataFrames, assert_series_equal for Series).","Inspect the error message: 'found <type>' tells you exactly what left is."],"exampleFix":"# before\nassert_series_equal([1, 2, 3], pd.Series([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\nleft = build_left()\nif not isinstance(left, pd.Series):\n    left = pd.Series(left)\nassert_series_equal(left, expected)","typeGuard":"import pandas as pd\n\ndef is_series(obj: object) -> bool:\n    return isinstance(obj, pd.Series)","tryCatchPattern":null,"preventionTips":["Always construct expected/actual with explicit pandas constructors in tests.","Pick the assert_*_equal function matching the operand type.","Run a quick isinstance(left, cls) before the assertion in helper code."],"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"}