Skip to content

EA: _can_hold_element, _validate_fill_value #36226

Closed
@jbrockmendel

Description

@jbrockmendel

TL;DR: we should add _validate_fill_value to the EA interface and define _can_hold_element in terms of it.

ATM ExtensionBlock._can_hold_element incorrectly always returns True. This needs to be an EA method that returns True if and only if self[0] = value is allowed on a non-empty array.

This method can in turn to defined in terms of a more broadly useful _validate_fill_value that we use DTA/TDA/PA/PandasArray/Categorical:

def _can_hold_element(self, value):
    try:
        self._validate_fill_value(value)
        return True
    except (ValueError, TypeError):
        return False

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignEnhancementExtensionArrayExtending pandas with custom dtypes or arrays.Needs DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions