{"record":{"id":"c0b47c270678dc13","repo":"pandas-dev/pandas","slug":"values-should-be-descr-numpy-array-use-the-pd","errorCode":null,"errorMessage":"values should be {descr} numpy array. Use the 'pd.array' function instead","messagePattern":"values should be (.+?) numpy array\\. Use the 'pd\\.array' function instead","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/numeric.py","lineNumber":269,"sourceCode":"\nclass NumericArray(BaseMaskedArray):\n    \"\"\"\n    Base class for IntegerArray and FloatingArray.\n    \"\"\"\n\n    _dtype_cls: type[NumericDtype]\n\n    def __init__(\n        self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False\n    ) -> None:\n        checker = self._dtype_cls._checker\n        if not (isinstance(values, np.ndarray) and checker(values.dtype)):\n            descr = (\n                \"floating\"\n                if self._dtype_cls.kind == \"f\"  # type: ignore[comparison-overlap]\n                else \"integer\"\n            )\n            raise TypeError(\n                f\"values should be {descr} numpy array. Use \"\n                \"the 'pd.array' function instead\"\n            )\n        if values.dtype == np.float16:\n            # If we don't raise here, then accessing self.dtype would raise\n            raise TypeError(\"FloatingArray does not support np.float16 dtype.\")\n\n        # NB: if is_nan_na() is True\n        #  then caller is responsible for ensuring\n        #  assert mask[np.isnan(values)].all()\n\n        super().__init__(values, mask, copy=copy)\n\n    @cache_readonly\n    def dtype(self) -> NumericDtype:\n        mapping = self._dtype_cls._get_dtype_mapping()\n        return mapping[self._data.dtype]\n","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/numeric.py#L251-L287","documentation":"Raised by NumericArray.__init__ when the values passed directly to the constructor are not a numpy ndarray of the correct numeric kind (integer for IntegerArray, floating for FloatingArray). The masked-array constructor is a low-level API expecting pre-validated _data/_mask buffers; user code should use pd.array(...) instead, which performs inference, casting, and mask construction.","triggerScenarios":"Calling IntegerArray(values, mask) or FloatingArray(values, mask) directly with values that are a Python list, an object array, or a numpy array of the wrong kind (e.g. IntegerArray(np.array([1.0,2.0]), mask)).","commonSituations":"Users reaching for the internal constructor instead of the public pd.array factory; passing already-float data to IntegerArray expecting automatic conversion.","solutions":["Use the public factory: pd.array(values, dtype='Int64').","If you must call the constructor, convert values first: IntegerArray(np.asarray(values, dtype=np.int64), mask).","Ensure values.dtype matches the array class's numpy_dtype."],"exampleFix":"// before\nIntegerArray([1, 2, 3], mask=[False, False, True])  # raises: values should be integer numpy array\n\n// after\npd.array([1, 2, None], dtype=\"Int64\")","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef validate_numeric_array_inputs(values, mask, kind):\n    arr = np.asarray(values)\n    if arr.dtype.kind != kind:\n        raise TypeError(f\"values must be {kind} numpy array, got {arr.dtype}\")\n    if np.asarray(mask).ndim != 1:\n        raise TypeError(\"mask must be 1D\")\n    return arr, np.asarray(mask, dtype=bool)","typeGuard":"def is_correct_kind_numpy(values, kind) -> bool:\n    import numpy as np\n    return isinstance(values, np.ndarray) and values.dtype.kind == kind","tryCatchPattern":"try:\n    arr = IntegerArray(values, mask)\nexcept TypeError as e:\n    if \"Use the 'pd.array' function instead\" in str(e):\n        arr = pd.array(values, dtype=\"Int64\")\n    else:\n        raise","preventionTips":["Use the public pd.array(...) factory instead of the NumericArray constructor.","If using the constructor, pre-convert values to the matching numpy dtype.","Add a unit test that values.dtype.kind matches the array class kind."],"tags":["numeric-array","constructor","dtype","api-misuse"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}