pandas-dev/pandas · error · NotImplementedError

{dtype}

Error message

{dtype}

What it means

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.

Source

Thrown at pandas/core/arrays/base.py:2154

        --------
        This gives view on the underlying data of an ``ExtensionArray`` and is not a
        copy. Modifications on either the view or the original ``ExtensionArray``
        will be reflected on the underlying data:

        >>> arr = pd.array([1, 2, 3])
        >>> arr2 = arr.view()
        >>> arr[0] = 2
        >>> arr2
        <IntegerArray>
        [2, 2, 3]
        Length: 3, dtype: Int64
        """
        # NB:
        # - This must return a *new* object referencing the same data, not self.
        # - The only case that *must* be implemented is with dtype=None,
        #   giving a view with the same dtype as self.
        if dtype is not None:
            raise NotImplementedError(dtype)
        return self[:]

    # ------------------------------------------------------------------------
    # Printing
    # ------------------------------------------------------------------------

    def __repr__(self) -> str:
        if self.ndim > 1:
            return self._repr_2d()

        from pandas.io.formats.printing import format_object_summary

        # the short repr has no trailing newline, while the truncated
        # repr does. So we include a newline in our template, and strip
        # any trailing newlines from format_object_summary
        data = format_object_summary(
            self, self._formatter(), indent_for_name=False
        ).rstrip(", \n")

View on GitHub (pinned to 3b7651241d)

Solutions

  1. Use astype(dtype) instead of view(dtype) when a copy-and-convert is acceptable (and is usually the correct pandas idiom for EAs).
  2. If zero-copy reinterpretation is genuinely needed, implement view on the subclass to reinterpret self._data and wrap appropriately.
  3. Call arr.view() with no argument for the same-dtype view, which the base supports.

Example fix

// before
out = arr.view('float64')  # NotImplementedError: float64

// after
out = arr.astype('float64')  # correct conversion for extension arrays
Defensive patterns

Strategy: validation

Validate before calling

if dtype is not None:
    # base view() only supports dtype=None for EAs
    out = arr.astype(dtype)
else:
    out = arr.view()

Try / catch

try:
    out = arr.view(requested_dtype)
except NotImplementedError:
    out = arr.astype(requested_dtype)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/ab635346a72bb113. Report an issue: GitHub.