Repository: pandas-dev/pandas
File: pandas/core/arrays/base.py (Python)

Code before:
    def _cast_pointwise_result(self, values: ArrayLike) -> ArrayLike:
        """
        Construct an ExtensionArray after a pointwise operation.

        Cast the result of a pointwise operation (e.g. Series.map) to an
        array. This is not required to return an ExtensionArray of the same
        type as self or of the same dtype. It can also return another
        ExtensionArray of the same "family" if you implement multiple
        ExtensionArrays/Dtypes that are interoperable (e.g. if you have float
        array with units, this method can return an int array with units).

        If converting to your own ExtensionArray is not possible, this method
        can raise an error (TypeError or ValueError) or return the input
        `values` as-is. Then pandas will do the further type inference.

        """
        try:
            return type(self)._from_scalars(values, dtype=self.dtype)
        except (ValueError, TypeError):
            return values

    # ------------------------------------------------------------------------
    # Must be a Sequence
    # ------------------------------------------------------------------------
    @overload
    def __getitem__(self, item: ScalarIndexer) -> Any: ...

    @overload
    def __getitem__(self, item: SequenceIndexer) -> Self: ...

    def __getitem__(self, item: PositionalIndexer) -> Self | Any:
        """
        Select a subset of self.

        Parameters
        ----------
        item : int, slice, or ndarray
            * int: The position in 'self' to get.

            * slice: A slice object, where 'start', 'stop', and 'step' are
              integers or None

            * ndarray: A 1-d boolean NumPy ndarray the same length as 'self'

            * list[int]:  A list of int

        Returns
        -------
        item : scalar or ExtensionArray

        Notes

Review comment (refactor):
IIUC this change is bc older geopandas implements _from_scalars?  can we catch+deprecate this so that we can eventually re-simplify this?

Code after:
    def _cast_pointwise_result(self, values) -> ArrayLike:
        """
        Construct an ExtensionArray after a pointwise operation.

        Cast the result of a pointwise operation (e.g. Series.map) to an
        array. This is not required to return an ExtensionArray of the same
        type as self or of the same dtype. It can also return another
        ExtensionArray of the same "family" if you implement multiple
        ExtensionArrays/Dtypes that are interoperable (e.g. if you have float
        array with units, this method can return an int array with units).

        If converting to your own ExtensionArray is not possible, this method
        falls back to returning an array with the default type inference.
        If you only need to cast to `self.dtype`, it is recommended to override
        `_from_scalars` instead of this method.

        Parameters
        ----------
        values : sequence

        Returns
        -------
        ExtensionArray or ndarray
        """
        try:
            return type(self)._from_scalars(values, dtype=self.dtype)
        except (ValueError, TypeError):
            values = np.asarray(values, dtype=object)
            return lib.maybe_convert_objects(values, convert_non_numeric=True)

    # ------------------------------------------------------------------------
    # Must be a Sequence
    # ------------------------------------------------------------------------
    @overload
    def __getitem__(self, item: ScalarIndexer) -> Any: ...

    @overload
    def __getitem__(self, item: SequenceIndexer) -> Self: ...

    def __getitem__(self, item: PositionalIndexer) -> Self | Any:
        """
        Select a subset of self.

        Parameters
        ----------
        item : int, slice, or ndarray
            * int: The position in 'self' to get.

            * slice: A slice object, where 'start', 'stop', and 'step' are
              integers or None