From 0b270053d083932b943d6a3f8e2fac4489895da8 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 24 Mar 2023 14:06:29 +0530 Subject: [PATCH 1/7] added tolist() --- pandas-stubs/core/arrays/base.pyi | 1 + tests/test_pandas.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/pandas-stubs/core/arrays/base.pyi b/pandas-stubs/core/arrays/base.pyi index 3694c0b92..7141f70ff 100644 --- a/pandas-stubs/core/arrays/base.pyi +++ b/pandas-stubs/core/arrays/base.pyi @@ -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 diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 4580fd6dd..f9d39ecce 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1973,3 +1973,10 @@ def g(x: pd.Series) -> int: ), pd.DataFrame, ) + + +def test_tolist() -> None: + data = {"Courses": "pandas", "Fees": 20000, "Duration": "30days"} + s = pd.Series(data) + listObj = s.tolist() + check(assert_type(listObj, list), list) From 01996b6b72a86ff525d36a1b88e2be827d3ede5d Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Fri, 24 Mar 2023 18:58:46 +0530 Subject: [PATCH 2/7] Update test_pandas.py --- tests/test_pandas.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index f9d39ecce..ab0d3d260 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1978,5 +1978,4 @@ def g(x: pd.Series) -> int: def test_tolist() -> None: data = {"Courses": "pandas", "Fees": 20000, "Duration": "30days"} s = pd.Series(data) - listObj = s.tolist() - check(assert_type(listObj, list), list) + check(assert_type(s.array.tolist(), list), list) From 49e5d55a7751bd4904683d1cf4b05dea03637dd8 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 25 Mar 2023 06:34:56 +0530 Subject: [PATCH 3/7] added the example --- tests/test_pandas.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index ab0d3d260..3f393d37c 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1976,6 +1976,9 @@ def g(x: pd.Series) -> int: def test_tolist() -> None: - data = {"Courses": "pandas", "Fees": 20000, "Duration": "30days"} + 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) From de2495cf36f77c7a3d6b49aa6656792bc45b870f Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 25 Mar 2023 22:05:46 +0530 Subject: [PATCH 4/7] Update test_pandas.py --- tests/test_pandas.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 3f393d37c..881c09a69 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1978,7 +1978,5 @@ def g(x: pd.Series) -> int: 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) From 9561c1fef1a94bf838c7fbcbf744d80b6dadc793 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 25 Mar 2023 22:07:19 +0530 Subject: [PATCH 5/7] Update test_pandas.py --- tests/test_pandas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 881c09a69..a4abe411c 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1979,4 +1979,4 @@ def test_tolist() -> None: data = {"State": "Texas", "Population": 2000000, "GDP": "2T"} s = pd.Series(data) check(assert_type(s.array.tolist(), list), list) - check(assert_type(pd.array([1,2,3]).tolist(), list), list) + check(assert_type(pd.array([1, 2, 3]).tolist(), list), list) From 2994e789cdfc0c671c6bd5ab076bf98276b2f3cf Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sun, 26 Mar 2023 22:25:16 +0530 Subject: [PATCH 6/7] added the test --- tests/test_extension.py | 8 ++++++++ tests/test_pandas.py | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test_extension.py b/tests/test_extension.py index 8714adfbe..4539b9f60 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -1,5 +1,6 @@ import decimal +import pandas as pd from typing_extensions import assert_type from tests import check @@ -14,3 +15,10 @@ 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) + check(assert_type(s.array.tolist(), list), list) + check(assert_type(pd.array([1, 2, 3]).tolist(), list), list) # type: ignore[call-arg] diff --git a/tests/test_pandas.py b/tests/test_pandas.py index a4abe411c..4580fd6dd 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1973,10 +1973,3 @@ def g(x: pd.Series) -> int: ), pd.DataFrame, ) - - -def test_tolist() -> None: - data = {"State": "Texas", "Population": 2000000, "GDP": "2T"} - s = pd.Series(data) - check(assert_type(s.array.tolist(), list), list) - check(assert_type(pd.array([1, 2, 3]).tolist(), list), list) From dc5268c90f8e3cc31622deffe4caa15b69a5baf3 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Mon, 27 Mar 2023 22:05:56 +0530 Subject: [PATCH 7/7] changed return type in array func and corrected the test --- pandas-stubs/core/construction.pyi | 4 ++-- tests/test_extension.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas-stubs/core/construction.pyi b/pandas-stubs/core/construction.pyi index 6b0cecdfd..09c671879 100644 --- a/pandas-stubs/core/construction.pyi +++ b/pandas-stubs/core/construction.pyi @@ -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 @@ -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 = ... diff --git a/tests/test_extension.py b/tests/test_extension.py index 4539b9f60..6784819dd 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -20,5 +20,8 @@ def test_constructor() -> None: 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(pd.array([1, 2, 3]).tolist(), list), list) # type: ignore[call-arg] + check(assert_type(s1.array.tolist(), list), list) + check(assert_type(pd.array([1, 2, 3]).tolist(), list), list)