{"record":{"id":"8a275e448c4d5593","repo":"microsoft/qlib","slug":"type-i-type-i","errorCode":null,"errorMessage":"type(i) = {type(i)}","messagePattern":"type\\(i\\) = (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"qlib/data/storage/file_storage.py","lineNumber":353,"sourceCode":"        with self.uri.open(\"rb\") as fp:\n            index = int(np.frombuffer(fp.read(4), dtype=\"<f\")[0])\n        return index\n\n    @property\n    def end_index(self) -> Union[int, None]:\n        if not self.uri.exists():\n            return None\n        # The next  data appending index point will be  `end_index + 1`\n        return self.start_index + len(self) - 1\n\n    def __getitem__(self, i: Union[int, slice]) -> Union[Tuple[int, float], pd.Series]:\n        if not self.uri.exists():\n            if isinstance(i, int):\n                return None, None\n            elif isinstance(i, slice):\n                return pd.Series(dtype=np.float32)\n            else:\n                raise TypeError(f\"type(i) = {type(i)}\")\n\n        storage_start_index = self.start_index\n        storage_end_index = self.end_index\n        with self.uri.open(\"rb\") as fp:\n            if isinstance(i, int):\n                if storage_start_index > i:\n                    raise IndexError(f\"{i}: start index is {storage_start_index}\")\n                fp.seek(4 * (i - storage_start_index) + 4)\n                return i, struct.unpack(\"f\", fp.read(4))[0]\n            elif isinstance(i, slice):\n                start_index = storage_start_index if i.start is None else i.start\n                end_index = storage_end_index if i.stop is None else i.stop - 1\n                si = max(start_index, storage_start_index)\n                if si > end_index:\n                    return pd.Series(dtype=np.float32)\n                fp.seek(4 * (si - storage_start_index) + 4)\n                # read n bytes\n                count = end_index - si + 1","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/data/storage/file_storage.py#L335-L371","documentation":"Raised by FileFeatureStorage.__getitem__ (qlib/data/storage/file_storage.py) in its missing-file branch: when the bin file does not exist and the index argument is neither int nor slice, there is nothing sensible to return, so a TypeError reporting the actual type is raised. It parallels the same check in the exists-file branch (error 399) but fires before any file I/O.","triggerScenarios":"feature_storage[n] where the storage bin file is absent and n is a float (1.0), numpy scalar, string, None, or a list of indices. The int and slice cases return (None, None) / empty Series; everything else errors.","commonSituations":"Code that indexes storages with numpy ints or arrays; None defaults reaching the index expression; probing storage contents for instruments whose data was never dumped.","solutions":["Index with a plain int or a slice only: storage[0], storage[10:20].","Convert numpy scalars with int(n) and use slices or repeated int indexing instead of lists of positions.","Ensure the bin file exists (dump the data) if you expected real values rather than the empty-result path."],"exampleFix":"# before\nval = feature_storage[np.int64(5)]  # file missing -> TypeError\n\n# after\nval = feature_storage[int(np.int64(5))]","handlingStrategy":"type-guard","validationCode":"if not isinstance(i, (int, slice)):\n    i = int(i)  # or convert list->slice, float->int","typeGuard":"def is_storage_index(i) -> bool:\n    return isinstance(i, (int, slice)) and not isinstance(i, bool)","tryCatchPattern":null,"preventionTips":["Only index storages with plain int or slice.","Convert numpy scalars with int() at the boundary of your code."],"tags":["qlib","storage","indexing","type-error"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}