{"record":{"id":"539e87ee49bbe7a8","repo":"TheAlgorithms/Python","slug":"the-parameter-idx-original-string-type-must-be-int","errorCode":null,"errorMessage":"The parameter idx_original_string type must be int or passive of cast to int.","messagePattern":"The parameter idx_original_string type must be int or passive of cast to int\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"data_compression/burrows_wheeler.py","lineNumber":146,"sourceCode":"    ValueError: The parameter idx_original_string must not be lower than 0.\n    >>> reverse_bwt(\"mnpbnnaaaaaa\", 12) # doctest: +NORMALIZE_WHITESPACE\n    Traceback (most recent call last):\n        ...\n    ValueError: The parameter idx_original_string must be lower than\n    len(bwt_string).\n    >>> reverse_bwt(\"mnpbnnaaaaaa\", 11.0)\n    'panamabanana'\n    >>> reverse_bwt(\"mnpbnnaaaaaa\", 11.4)\n    'panamabanana'\n    \"\"\"\n    if not isinstance(bwt_string, str):\n        raise TypeError(\"The parameter bwt_string type must be str.\")\n    if not bwt_string:\n        raise ValueError(\"The parameter bwt_string must not be empty.\")\n    try:\n        idx_original_string = int(idx_original_string)\n    except ValueError:\n        raise TypeError(\n            \"The parameter idx_original_string type must be int or passive\"\n            \" of cast to int.\"\n        )\n    if idx_original_string < 0:\n        raise ValueError(\"The parameter idx_original_string must not be lower than 0.\")\n    if idx_original_string >= len(bwt_string):\n        raise ValueError(\n            \"The parameter idx_original_string must be lower than len(bwt_string).\"\n        )\n\n    ordered_rotations = [\"\"] * len(bwt_string)\n    for _ in range(len(bwt_string)):\n        for i in range(len(bwt_string)):\n            ordered_rotations[i] = bwt_string[i] + ordered_rotations[i]\n        ordered_rotations.sort()\n    return ordered_rotations[idx_original_string]\n\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_compression/burrows_wheeler.py#L128-L164","documentation":"Raised by reverse_bwt() in data_compression/burrows_wheeler.py when idx_original_string cannot be cast to int via int(). Note the try block catches ValueError only, so floats like 11.0 and 11.4 are accepted (truncated), while non-numeric strings ('11') and None raise this TypeError. Also note complex numbers with an imaginary part raise TypeError inside int() and are not caught by this handler, escaping as a different message.","triggerScenarios":"Calling reverse_bwt('mnpbnnaaaaaa', '11'), reverse_bwt('mnpbnnaaaaaa', None), or reverse_bwt('mnpbnnaaaaaa', [11]). Passing 11.0 or 11.4 does NOT trigger it — those cast fine per the doctests.","commonSituations":"Loading the index from JSON/config/CLI where it arrives as a string like '11' and is not converted to int; a None default slipping through from an optional field; type drift after refactoring.","solutions":["Convert to int at the call site: reverse_bwt(bwt_str, int(idx_str)).","Validate the payload schema so idx is stored/loaded as an integer, not a string.","Be aware floats are silently truncated (11.4 becomes 11) — pass real ints to avoid surprising behavior even though it does not raise."],"exampleFix":"# before\nreverse_bwt('mnpbnnaaaaaa', '11')  # TypeError\n\n# after\nreverse_bwt('mnpbnnaaaaaa', int('11'))  # 'panamabanana'","handlingStrategy":"type-guard","validationCode":"idx = int(idx_original_string)  # raises early with your own context\nplain = reverse_bwt(bwt_string, idx)","typeGuard":"def is_int_coercible(value: object) -> bool:\n    try:\n        int(value)\n        return True\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    plain = reverse_bwt(bwt_string, idx)\nexcept TypeError:\n    raise ValueError(f'idx {idx!r} is not numeric') from None","preventionTips":["Convert string indexes with int() at the parse boundary","Store/serialize the BWT index as a JSON number, not a string","Watch out: float indexes are silently truncated to int"],"tags":["type-validation","burrows-wheeler","type-coercion","compression"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}