{"record":{"id":"010d637640c8bde2","repo":"babysor/MockingBird","slug":"has-real-and-imag-keys","errorCode":null,"errorMessage":"has 'real' and 'imag' keys: {}","messagePattern":"has 'real' and 'imag' keys: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"models/ppg_extractor/nets_utils.py","lineNumber":350,"sourceCode":"        )\n\n    \"\"\"\n    # If numpy, change to torch tensor\n    if isinstance(x, np.ndarray):\n        if x.dtype.kind == 'c':\n            # Dynamically importing because torch_complex requires python3\n            from torch_complex.tensor import ComplexTensor\n            return ComplexTensor(x)\n        else:\n            return torch.from_numpy(x)\n\n    # If {'real': ..., 'imag': ...}, convert to ComplexTensor\n    elif isinstance(x, dict):\n        # Dynamically importing because torch_complex requires python3\n        from torch_complex.tensor import ComplexTensor\n\n        if 'real' not in x or 'imag' not in x:\n            raise ValueError(\"has 'real' and 'imag' keys: {}\".format(list(x)))\n        # Relative importing because of using python3 syntax\n        return ComplexTensor(x['real'], x['imag'])\n\n    # If torch.Tensor, as it is\n    elif isinstance(x, torch.Tensor):\n        return x\n\n    else:\n        error = (\"x must be numpy.ndarray, torch.Tensor or a dict like \"\n                 \"{{'real': torch.Tensor, 'imag': torch.Tensor}}, \"\n                 \"but got {}\".format(type(x)))\n        try:\n            from torch_complex.tensor import ComplexTensor\n        except Exception:\n            # If PY2\n            raise ValueError(error)\n        else:\n            # If PY3","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/babysor/MockingBird/blob/28dc5e14f12d7c754612af2fde8e78a4b03f8616/models/ppg_extractor/nets_utils.py#L332-L368","documentation":"to_torch_tensor converts dict inputs to ComplexTensor, but only if the dict has both 'real' and 'imag' keys. A dict missing either key raises ValueError listing the actual keys present.","triggerScenarios":"Passing a dict to to_torch_tensor whose keys are not exactly containing 'real' and 'imag', e.g. {'re': ..., 'im': ...} or a features dict with other metadata keys.","commonSituations":"Loading numpy complex features saved as dicts with different key names; feeding a generic feature dict where a complex tensor was expected.","solutions":["Rename keys to 'real' and 'imag' before calling","Pass torch.Tensor or numpy array directly if the data is real-valued","Inspect x.keys() in the error message to see what you actually passed"],"exampleFix":"# before\nx = {'re': a, 'im': b}\nt = to_torch_tensor(x)\n\n# after\nx = {'real': a, 'imag': b}\nt = to_torch_tensor(x)","handlingStrategy":"type-guard","validationCode":"if isinstance(x, dict):\n    assert {'real', 'imag'} <= set(x.keys()), f'keys: {list(x)}'","typeGuard":"def is_complex_dict(x) -> bool:\n    return isinstance(x, dict) and 'real' in x and 'imag' in x","tryCatchPattern":null,"preventionTips":["Standardize complex feature serialization to {'real','imag'}","Read the key list in the error message to debug what dict you passed"],"tags":["complex-tensor","preprocessing","valueerror"],"backgroundTag":"unexpected-input-shape","analyzedSha":"28dc5e14f12d7c754612af2fde8e78a4b03f8616","analyzedAt":"2026-08-27T02:26:53.589Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}