{"record":{"id":"ab635346a72bb113","repo":"pandas-dev/pandas","slug":"dtype","errorCode":null,"errorMessage":"{dtype}","messagePattern":"\\{dtype\\}","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/base.py","lineNumber":2154,"sourceCode":"        --------\n        This gives view on the underlying data of an ``ExtensionArray`` and is not a\n        copy. Modifications on either the view or the original ``ExtensionArray``\n        will be reflected on the underlying data:\n\n        >>> arr = pd.array([1, 2, 3])\n        >>> arr2 = arr.view()\n        >>> arr[0] = 2\n        >>> arr2\n        <IntegerArray>\n        [2, 2, 3]\n        Length: 3, dtype: Int64\n        \"\"\"\n        # NB:\n        # - This must return a *new* object referencing the same data, not self.\n        # - The only case that *must* be implemented is with dtype=None,\n        #   giving a view with the same dtype as self.\n        if dtype is not None:\n            raise NotImplementedError(dtype)\n        return self[:]\n\n    # ------------------------------------------------------------------------\n    # Printing\n    # ------------------------------------------------------------------------\n\n    def __repr__(self) -> str:\n        if self.ndim > 1:\n            return self._repr_2d()\n\n        from pandas.io.formats.printing import format_object_summary\n\n        # the short repr has no trailing newline, while the truncated\n        # repr does. So we include a newline in our template, and strip\n        # any trailing newlines from format_object_summary\n        data = format_object_summary(\n            self, self._formatter(), indent_for_name=False\n        ).rstrip(\", \\n\")","sourceCodeStart":2136,"sourceCodeEnd":2172,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/base.py#L2136-L2172","documentation":"ExtensionArray.view(dtype) base implementation only supports dtype=None, returning a same-dtype view of the underlying data. Passing any other dtype raises NotImplementedError echoing the requested dtype, because reinterpretation (e.g. viewing an Int64 array as float64, or a numeric array as a structured dtype) is storage-layout-specific and must be implemented by the subclass. The source note stresses the result must be a new object sharing the buffer, not self.","triggerScenarios":"Calling arr.view('float64') or arr.view(some_dtype) on an ExtensionArray whose class did not override view for that dtype. Often reached via Series.view or internal astype(view-like) paths.","commonSituations":"Porting numpy ndarray.view code to an EA-backed Series. Attempting a zero-copy reinterpretation on a nullable/extension dtype (Int64, Float64, string) where physical storage differs from the logical type.","solutions":["Use astype(dtype) instead of view(dtype) when a copy-and-convert is acceptable (and is usually the correct pandas idiom for EAs).","If zero-copy reinterpretation is genuinely needed, implement view on the subclass to reinterpret self._data and wrap appropriately.","Call arr.view() with no argument for the same-dtype view, which the base supports."],"exampleFix":"// before\nout = arr.view('float64')  # NotImplementedError: float64\n\n// after\nout = arr.astype('float64')  # correct conversion for extension arrays","handlingStrategy":"validation","validationCode":"if dtype is not None:\n    # base view() only supports dtype=None for EAs\n    out = arr.astype(dtype)\nelse:\n    out = arr.view()","typeGuard":null,"tryCatchPattern":"try:\n    out = arr.view(requested_dtype)\nexcept NotImplementedError:\n    out = arr.astype(requested_dtype)","preventionTips":["Prefer astype over view for extension arrays; view's zero-copy semantics rarely apply.","Use bare arr.view() (no argument) when you only need a same-dtype view.","Implement view(dtype) on the subclass only if you genuinely need zero-copy reinterpretation."],"tags":["extension-array","not-implemented","view","dtype","pandas"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}