From 7e60f62c506f16b229152d9c45c6b584a7257442 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Mon, 29 May 2023 17:43:30 +0530 Subject: [PATCH 1/3] added new `is_any_real_numeric_dtype` function and added `None` to `na_values` in read_csv --- pandas-stubs/core/dtypes/common.pyi | 1 + pandas-stubs/io/parsers/readers.pyi | 6 +++--- tests/test_dtypes.py | 8 ++++++++ tests/test_io.py | 6 ++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pandas-stubs/core/dtypes/common.pyi b/pandas-stubs/core/dtypes/common.pyi index 5147c2752..8a0a95edc 100644 --- a/pandas-stubs/core/dtypes/common.pyi +++ b/pandas-stubs/core/dtypes/common.pyi @@ -53,4 +53,5 @@ def is_float_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_bool_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_extension_array_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_complex_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... +def is_any_real_numeric_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def pandas_dtype(dtype: object) -> DtypeObj: ... diff --git a/pandas-stubs/io/parsers/readers.pyi b/pandas-stubs/io/parsers/readers.pyi index e25a96be8..1db4a429c 100644 --- a/pandas-stubs/io/parsers/readers.pyi +++ b/pandas-stubs/io/parsers/readers.pyi @@ -57,7 +57,7 @@ def read_csv( skiprows: int | Sequence[int] | Callable[[int], bool] = ..., skipfooter: int = ..., nrows: int | None = ..., - na_values: Sequence[str] | Mapping[str, Sequence[str]] = ..., + na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., verbose: bool = ..., @@ -117,7 +117,7 @@ def read_csv( skiprows: int | Sequence[int] | Callable[[int], bool] = ..., skipfooter: int = ..., nrows: int | None = ..., - na_values: Sequence[str] | Mapping[str, Sequence[str]] = ..., + na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., verbose: bool = ..., @@ -177,7 +177,7 @@ def read_csv( skiprows: int | Sequence[int] | Callable[[int], bool] = ..., skipfooter: int = ..., nrows: int | None = ..., - na_values: Sequence[str] | Mapping[str, Sequence[str]] = ..., + na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., verbose: bool = ..., diff --git a/tests/test_dtypes.py b/tests/test_dtypes.py index 53c8d81eb..d65803673 100644 --- a/tests/test_dtypes.py +++ b/tests/test_dtypes.py @@ -22,6 +22,8 @@ from pandas._libs.missing import NAType from pandas._typing import Scalar +from pandas.core.dtypes.common import is_any_real_numeric_dtype + from tests import ( TYPE_CHECKING_INVALID_USAGE, check, @@ -144,3 +146,9 @@ def test_arrow_dtype() -> None: a_dt = pd.ArrowDtype(pa.int64()) check(assert_type(a_dt, pd.ArrowDtype), pd.ArrowDtype) check(assert_type(a_dt.pyarrow_dtype, pa.DataType), pa.DataType) + + +def test_is_any_real_numeric_dtype() -> None: + check(assert_type(is_any_real_numeric_dtype(np.array([1, 2])), bool), bool) + check(assert_type(is_any_real_numeric_dtype(int), bool), bool) + check(assert_type(is_any_real_numeric_dtype(float), bool), bool) diff --git a/tests/test_io.py b/tests/test_io.py index 92549ac0a..1567496a7 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -1506,3 +1506,9 @@ def test_added_date_format() -> None: ), pd.DataFrame, ) + + +def test_read_csv_name_none() -> None: + with ensure_clean() as path: + check(assert_type(DF.to_csv(path), None), type(None)) + check(assert_type(read_csv(path, na_values=None), DataFrame), DataFrame) From b5a691f39f17fca6fdd88bae3f4485a75cb8a38b Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 3 Jun 2023 11:20:34 +0530 Subject: [PATCH 2/3] update added import statement in new files and deleted unimp. args --- pandas-stubs/api/types/__init__.pyi | 3 +++ pandas-stubs/io/parsers/readers.pyi | 6 +++--- tests/test_dtypes.py | 3 +-- tests/test_io.py | 6 ------ 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pandas-stubs/api/types/__init__.pyi b/pandas-stubs/api/types/__init__.pyi index 3a5292a18..04e7de2cc 100644 --- a/pandas-stubs/api/types/__init__.pyi +++ b/pandas-stubs/api/types/__init__.pyi @@ -41,6 +41,9 @@ from pandas.core.dtypes.api import ( is_unsigned_integer_dtype as is_unsigned_integer_dtype, pandas_dtype as pandas_dtype, ) +from pandas.core.dtypes.common import ( + is_any_real_numeric_dtype as is_any_real_numeric_dtype, +) from pandas.core.dtypes.concat import union_categoricals as union_categoricals from pandas.core.dtypes.dtypes import ( CategoricalDtype as CategoricalDtype, diff --git a/pandas-stubs/io/parsers/readers.pyi b/pandas-stubs/io/parsers/readers.pyi index 1db4a429c..e25a96be8 100644 --- a/pandas-stubs/io/parsers/readers.pyi +++ b/pandas-stubs/io/parsers/readers.pyi @@ -57,7 +57,7 @@ def read_csv( skiprows: int | Sequence[int] | Callable[[int], bool] = ..., skipfooter: int = ..., nrows: int | None = ..., - na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., + na_values: Sequence[str] | Mapping[str, Sequence[str]] = ..., keep_default_na: bool = ..., na_filter: bool = ..., verbose: bool = ..., @@ -117,7 +117,7 @@ def read_csv( skiprows: int | Sequence[int] | Callable[[int], bool] = ..., skipfooter: int = ..., nrows: int | None = ..., - na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., + na_values: Sequence[str] | Mapping[str, Sequence[str]] = ..., keep_default_na: bool = ..., na_filter: bool = ..., verbose: bool = ..., @@ -177,7 +177,7 @@ def read_csv( skiprows: int | Sequence[int] | Callable[[int], bool] = ..., skipfooter: int = ..., nrows: int | None = ..., - na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., + na_values: Sequence[str] | Mapping[str, Sequence[str]] = ..., keep_default_na: bool = ..., na_filter: bool = ..., verbose: bool = ..., diff --git a/tests/test_dtypes.py b/tests/test_dtypes.py index d65803673..68c8f98be 100644 --- a/tests/test_dtypes.py +++ b/tests/test_dtypes.py @@ -13,6 +13,7 @@ import numpy as np import pandas as pd +from pandas.api.types import is_any_real_numeric_dtype from pandas.core.arrays import BooleanArray # noqa: F401 from pandas.core.arrays import IntegerArray # noqa: F401 import pyarrow as pa @@ -22,8 +23,6 @@ from pandas._libs.missing import NAType from pandas._typing import Scalar -from pandas.core.dtypes.common import is_any_real_numeric_dtype - from tests import ( TYPE_CHECKING_INVALID_USAGE, check, diff --git a/tests/test_io.py b/tests/test_io.py index 1567496a7..92549ac0a 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -1506,9 +1506,3 @@ def test_added_date_format() -> None: ), pd.DataFrame, ) - - -def test_read_csv_name_none() -> None: - with ensure_clean() as path: - check(assert_type(DF.to_csv(path), None), type(None)) - check(assert_type(read_csv(path, na_values=None), DataFrame), DataFrame) From f8b92314257cf9789c709d4dc183f2d4544b94f1 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sun, 4 Jun 2023 23:54:42 +0530 Subject: [PATCH 3/3] updated the file for import statement --- pandas-stubs/api/types/__init__.pyi | 4 +--- pandas-stubs/core/dtypes/api.pyi | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas-stubs/api/types/__init__.pyi b/pandas-stubs/api/types/__init__.pyi index 04e7de2cc..bfdaa105b 100644 --- a/pandas-stubs/api/types/__init__.pyi +++ b/pandas-stubs/api/types/__init__.pyi @@ -1,6 +1,7 @@ from pandas._libs.lib import infer_dtype as infer_dtype from pandas.core.dtypes.api import ( + is_any_real_numeric_dtype as is_any_real_numeric_dtype, is_array_like as is_array_like, is_bool as is_bool, is_bool_dtype as is_bool_dtype, @@ -41,9 +42,6 @@ from pandas.core.dtypes.api import ( is_unsigned_integer_dtype as is_unsigned_integer_dtype, pandas_dtype as pandas_dtype, ) -from pandas.core.dtypes.common import ( - is_any_real_numeric_dtype as is_any_real_numeric_dtype, -) from pandas.core.dtypes.concat import union_categoricals as union_categoricals from pandas.core.dtypes.dtypes import ( CategoricalDtype as CategoricalDtype, diff --git a/pandas-stubs/core/dtypes/api.pyi b/pandas-stubs/core/dtypes/api.pyi index 89fc968de..e52ace018 100644 --- a/pandas-stubs/core/dtypes/api.pyi +++ b/pandas-stubs/core/dtypes/api.pyi @@ -1,4 +1,5 @@ from pandas.core.dtypes.common import ( + is_any_real_numeric_dtype as is_any_real_numeric_dtype, is_array_like as is_array_like, is_bool as is_bool, is_bool_dtype as is_bool_dtype,