Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas-stubs/core/arrays/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ExtensionArray:
def copy(self) -> Self: ...
def view(self, dtype=...) -> Self | np.ndarray: ...
def ravel(self, order=...) -> Self: ...
def tolist(self) -> list: ...

class ExtensionOpsMixin:
@classmethod
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/construction.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Sequence

import numpy as np
from pandas.core.arrays.base import ExtensionArray
from pandas.core.indexes.api import Index
from pandas.core.series import Series

Expand All @@ -10,13 +11,12 @@ from pandas._typing import (
)

from pandas.core.dtypes.dtypes import ExtensionDtype
from pandas.core.dtypes.generic import ABCExtensionArray

def array(
data: Sequence[object],
dtype: str | np.dtype | ExtensionDtype | None = ...,
copy: bool = ...,
) -> ABCExtensionArray: ...
) -> ExtensionArray: ...
def extract_array(obj, extract_numpy: bool = ...): ...
def sanitize_array(
data, index, dtype=..., copy: bool = ..., raise_cast_failure: bool = ...
Expand Down
11 changes: 11 additions & 0 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import decimal

import pandas as pd
from typing_extensions import assert_type

from tests import check
Expand All @@ -14,3 +15,13 @@ def test_constructor() -> None:

check(assert_type(arr, DecimalArray), DecimalArray, decimal.Decimal)
check(assert_type(arr.dtype, DecimalDtype), DecimalDtype)


def test_tolist() -> None:
data = {"State": "Texas", "Population": 2000000, "GDP": "2T"}
s = pd.Series(data)
data1 = [1, 2, 3]
s1 = pd.Series(data1)
check(assert_type(s.array.tolist(), list), list)
check(assert_type(s1.array.tolist(), list), list)
check(assert_type(pd.array([1, 2, 3]).tolist(), list), list)