{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/numeric.py#L251-L287","documentation":"Raised by NumericArray.__init__ when the values argument is not a NumPy array whose dtype passes the dtype class's _checker (is_integer_dtype for IntegerArray, is_floating_dtype for FloatingArray). The constructor is the low-level path: it expects raw, correctly-typed data plus a mask. The error message explicitly redirects users to pd.array(), which runs full coercion (_coerce_to_data_and_mask) including dtype inference and casting.","triggerScenarios":"pd.arrays.IntegerArray(np.array([1.5, 2.0]), mask=np.zeros(2, bool)) — float values into integer array. pd.arrays.FloatingArray(np.array([1, 2], dtype='int64'), mask=...) — integer values into floating array. Constructing directly from a Python list.","commonSituations":"Users discovering pd.arrays.IntegerArray / FloatingArray and calling the constructor directly instead of the documented pd.array() factory; internal code that forgot to coerce before reaching __init__.","solutions":["Use the public factory: pd.array(values, dtype='Int64') or pd.array(values, dtype='Float64').","If you must call the constructor, pre-coerce values to the right numpy kind: np.asarray(values, dtype=np.int64) for IntegerArray, np.float64 for FloatingArray.","Construct via the Series astype path: pd.Series(values).astype('Int64').array."],"exampleFix":"# before\npd.arrays.IntegerArray(np.array([1.5, 2.0]), mask=np.zeros(2, bool))  # raises\n\n# after\npd.array([1.5, 2.0], dtype='Int64')","handlingStrategy":"fallback","validationCode":"import numpy as np\n\ndef build_masked_array(values, mask, *, kind):\n    np_kind = {'int': 'int64', 'float': 'float64'}[kind]\n    values = np.asarray(values, dtype=np_kind)\n    # ensure the dtype class's _checker will pass\n    return values, np.asarray(mask, dtype=bool)","typeGuard":"def matches_numeric_kind(values, kind) -> bool:\n    import numpy as np\n    v = np.asarray(values)\n    return (kind == 'i' and v.dtype.kind in 'iu') or (kind == 'f' and v.dtype.kind == 'f')","tryCatchPattern":"# Prefer: don't catch — just use the factory.\npd.array(values, dtype='Int64')  # runs full coercion","preventionTips":["Use pd.array(values, dtype=...) instead of calling IntegerArray/FloatingArray constructors directly.","If you must call the constructor, pre-coerce with np.asarray(values, dtype=np.int64/np.float64).","Treat the constructor as internal; the factory is the public contract."],"tags":["pandas","masked-array","numeric","constructor","dtype"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}