Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Improve api.types #274

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions pandas-stubs/_libs/lib.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
no_default = None

def infer_dtype(value: object, skipna: bool = ...) -> str: ...
def is_iterator(obj: object) -> bool: ...
def is_scalar(val: object) -> bool: ...

# TODO: Add to pandas docs
def is_decimal(val: object) -> bool: ...
def is_list_like(obj: object, allow_sets: bool = ...) -> bool: ...

# TODO: Add to pandas docs
def is_period(val: object) -> bool: ...
bashtage marked this conversation as resolved.
Show resolved Hide resolved
def is_interval(val: object) -> bool: ...
def is_complex(val: object) -> bool: ...
def is_bool(val: object) -> bool: ...
def is_integer(val: object) -> bool: ...
def is_float(val: object) -> bool: ...
2 changes: 0 additions & 2 deletions pandas-stubs/api/extensions/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ from pandas.core.arrays import (
ExtensionScalarOpsMixin as ExtensionScalarOpsMixin,
)

from pandas._libs.lib import no_default as no_default

from pandas.core.dtypes.dtypes import (
ExtensionDtype as ExtensionDtype,
register_extension_dtype as register_extension_dtype,
Expand Down
2 changes: 0 additions & 2 deletions pandas-stubs/api/types/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from pandas.core.dtypes.api import (
is_array_like as is_array_like,
is_bool as is_bool,
is_bool_dtype as is_bool_dtype,
is_categorical as is_categorical,
bashtage marked this conversation as resolved.
Show resolved Hide resolved
is_categorical_dtype as is_categorical_dtype,
is_complex as is_complex,
is_complex_dtype as is_complex_dtype,
Expand All @@ -15,7 +14,6 @@ from pandas.core.dtypes.api import (
is_dict_like as is_dict_like,
is_dtype_equal as is_dtype_equal,
is_extension_array_dtype as is_extension_array_dtype,
is_extension_type as is_extension_type,
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
is_file_like as is_file_like,
is_float as is_float,
is_float_dtype as is_float_dtype,
Expand Down
6 changes: 1 addition & 5 deletions pandas-stubs/core/arrays/sparse/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ from .accessor import (
SparseAccessor as SparseAccessor,
SparseFrameAccessor as SparseFrameAccessor,
)
from .array import (
BlockIndex as BlockIndex,
IntIndex as IntIndex,
SparseArray as SparseArray,
)
from .array import SparseArray as SparseArray
from .dtype import SparseDtype as SparseDtype
9 changes: 1 addition & 8 deletions pandas-stubs/core/arrays/sparse/accessor.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from pandas.core.accessor import (
PandasDelegate as PandasDelegate,
delegate_names as delegate_names,
)
from pandas.core.arrays.sparse.array import SparseArray as SparseArray
from pandas.core.arrays.sparse.dtype import SparseDtype as SparseDtype

from pandas.core.dtypes.cast import find_common_type as find_common_type
from pandas.core.accessor import PandasDelegate

class BaseAccessor:
def __init__(self, data=...) -> None: ...
Expand Down
37 changes: 1 addition & 36 deletions pandas-stubs/core/arrays/sparse/array.pyi
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
import numpy as np
from pandas.core.arrays import (
ExtensionArray as ExtensionArray,
ExtensionArray,
ExtensionOpsMixin,
)
from pandas.core.arrays.sparse.dtype import SparseDtype as SparseDtype
from pandas.core.base import PandasObject as PandasObject
from pandas.core.construction import sanitize_array as sanitize_array
from pandas.core.indexers import check_array_indexer as check_array_indexer
from pandas.core.missing import interpolate_2d as interpolate_2d

from pandas._libs.sparse import (
BlockIndex as BlockIndex,
IntIndex as IntIndex,
SparseIndex as SparseIndex,
)
from pandas._libs.tslibs import NaT as NaT
from pandas.errors import PerformanceWarning as PerformanceWarning

from pandas.core.dtypes.cast import (
astype_nansafe as astype_nansafe,
construct_1d_arraylike_from_scalar as construct_1d_arraylike_from_scalar,
find_common_type as find_common_type,
)
from pandas.core.dtypes.common import (
is_array_like as is_array_like,
is_bool_dtype as is_bool_dtype,
is_datetime64_any_dtype as is_datetime64_any_dtype,
is_dtype_equal as is_dtype_equal,
is_integer as is_integer,
is_object_dtype as is_object_dtype,
is_scalar as is_scalar,
is_string_dtype as is_string_dtype,
pandas_dtype as pandas_dtype,
)
from pandas.core.dtypes.generic import ABCSeries as ABCSeries
from pandas.core.dtypes.missing import (
isna as isna,
na_value_for_dtype as na_value_for_dtype,
notna as notna,
)

class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin):
def __init__(
Expand Down
14 changes: 1 addition & 13 deletions pandas-stubs/core/arrays/sparse/dtype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ from pandas._typing import (
Scalar,
)

from pandas.core.dtypes.base import ExtensionDtype as ExtensionDtype
from pandas.core.dtypes.cast import astype_nansafe as astype_nansafe
from pandas.core.dtypes.common import (
is_bool_dtype as is_bool_dtype,
is_object_dtype as is_object_dtype,
is_scalar as is_scalar,
is_string_dtype as is_string_dtype,
pandas_dtype as pandas_dtype,
)
from pandas.core.dtypes.base import ExtensionDtype
from pandas.core.dtypes.dtypes import (
register_extension_dtype as register_extension_dtype,
)
from pandas.core.dtypes.missing import (
isna as isna,
na_value_for_dtype as na_value_for_dtype,
)

# merged types from pylance

Expand Down
2 changes: 0 additions & 2 deletions pandas-stubs/core/dtypes/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ from pandas.core.dtypes.common import (
is_array_like as is_array_like,
is_bool as is_bool,
is_bool_dtype as is_bool_dtype,
is_categorical as is_categorical,
is_categorical_dtype as is_categorical_dtype,
is_complex as is_complex,
is_complex_dtype as is_complex_dtype,
Expand All @@ -13,7 +12,6 @@ from pandas.core.dtypes.common import (
is_dict_like as is_dict_like,
is_dtype_equal as is_dtype_equal,
is_extension_array_dtype as is_extension_array_dtype,
is_extension_type as is_extension_type,
is_file_like as is_file_like,
is_float as is_float,
is_float_dtype as is_float_dtype,
Expand Down
28 changes: 0 additions & 28 deletions pandas-stubs/core/dtypes/cast.pyi
Original file line number Diff line number Diff line change
@@ -1,28 +0,0 @@
import numpy as np

from pandas._typing import Dtype

def is_nested_object(obj) -> bool: ...
def infer_dtype_from(val, pandas_dtype: bool = ...): ...
def infer_dtype_from_scalar(val, pandas_dtype: bool = ...): ...
def infer_dtype_from_array(arr, pandas_dtype: bool = ...): ...
def invalidate_string_dtypes(dtype_set) -> None: ...
def coerce_indexer_dtype(indexer, categories): ...
def astype_nansafe(arr, dtype, copy: bool = ..., skipna: bool = ...): ...
def soft_convert_objects(
values: np.ndarray,
datetime: bool = ...,
numeric: bool = ...,
timedelta: bool = ...,
coerce: bool = ...,
copy: bool = ...,
): ...
def convert_dtypes(
input_array,
convert_string: bool = ...,
convert_integer: bool = ...,
convert_boolean: bool = ...,
) -> Dtype: ...
def find_common_type(types): ...
def construct_1d_arraylike_from_scalar(value, length: int, dtype): ...
def construct_1d_object_array_from_listlike(values): ...
66 changes: 32 additions & 34 deletions pandas-stubs/core/dtypes/common.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from typing import Callable
from typing import Union

import numpy as np
import pandas as pd

from pandas._typing import (
ArrayLike,
DtypeObj,
npt,
)

from pandas.core.dtypes.inference import (
is_array_like as is_array_like,
Expand All @@ -21,37 +28,28 @@ from pandas.core.dtypes.inference import (
is_scalar as is_scalar,
)

def classes(*klasses) -> Callable: ...
def classes_and_not_datetimelike(*klasses) -> Callable: ...
def is_object_dtype(arr_or_dtype) -> bool: ...
def is_sparse(arr) -> bool: ...
def is_scipy_sparse(arr) -> bool: ...
def is_categorical(arr) -> bool: ...
def is_datetime64_dtype(arr_or_dtype) -> bool: ...
def is_datetime64tz_dtype(arr_or_dtype) -> bool: ...
def is_timedelta64_dtype(arr_or_dtype) -> bool: ...
def is_period_dtype(arr_or_dtype) -> bool: ...
def is_interval_dtype(arr_or_dtype) -> bool: ...
def is_categorical_dtype(arr_or_dtype) -> bool: ...
def is_string_dtype(arr_or_dtype) -> bool: ...
_ArrayOrDtype = Union[ArrayLike, npt.DTypeLike, pd.Series, pd.DataFrame]

def is_object_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_sparse(arr: ArrayLike | pd.Series | pd.DataFrame) -> bool: ...
def is_datetime64_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_datetime64tz_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_timedelta64_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_period_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_dtype_equal(source, target) -> bool: ...
def is_any_int_dtype(arr_or_dtype) -> bool: ...
def is_integer_dtype(arr_or_dtype) -> bool: ...
def is_signed_integer_dtype(arr_or_dtype) -> bool: ...
def is_unsigned_integer_dtype(arr_or_dtype) -> bool: ...
def is_int64_dtype(arr_or_dtype) -> bool: ...
def is_datetime64_any_dtype(arr_or_dtype) -> bool: ...
def is_datetime64_ns_dtype(arr_or_dtype) -> bool: ...
def is_timedelta64_ns_dtype(arr_or_dtype) -> bool: ...
def is_datetime_or_timedelta_dtype(arr_or_dtype) -> bool: ...
def is_numeric_v_string_like(a, b): ...
def is_datetimelike_v_numeric(a, b): ...
def needs_i8_conversion(arr_or_dtype) -> bool: ...
def is_numeric_dtype(arr_or_dtype) -> bool: ...
def is_float_dtype(arr_or_dtype) -> bool: ...
def is_bool_dtype(arr_or_dtype) -> bool: ...
def is_extension_type(arr) -> bool: ...
def is_extension_array_dtype(arr_or_dtype) -> bool: ...
def is_complex_dtype(arr_or_dtype) -> bool: ...
def infer_dtype_from_object(dtype): ...
def pandas_dtype(dtype): ...
def is_interval_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_categorical_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_string_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_integer_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_signed_integer_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_unsigned_integer_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_int64_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_datetime64_any_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_datetime64_ns_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_timedelta64_ns_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
def is_numeric_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...
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 pandas_dtype(dtype: object) -> DtypeObj: ...
1 change: 0 additions & 1 deletion pandas-stubs/core/dtypes/concat.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
def concat_compat(to_concat, axis: int = ...): ...
def union_categoricals(
to_union, sort_categories: bool = ..., ignore_order: bool = ...
): ...
1 change: 0 additions & 1 deletion pandas-stubs/core/dtypes/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from typing import (
from pandas.core.indexes.base import Index

from pandas._libs.tslibs import ( # , timezones as timezones
NaT as NaT,
Period as Period,
Timestamp,
)
Expand Down
12 changes: 1 addition & 11 deletions pandas-stubs/core/dtypes/generic.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
from pandas import (
DataFrame,
Index,
Series,
)
from pandas import Series
from pandas.core.arrays import ExtensionArray
from pandas.core.generic import NDFrame

ABCIndex = type[Index]

ABCNDFrame = type[NDFrame]
ABCSeries = type[Series]
ABCDataFrame = type[DataFrame]

ABCExtensionArray = type[ExtensionArray]
39 changes: 20 additions & 19 deletions pandas-stubs/core/dtypes/inference.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
def is_bool(obj) -> bool: ...
def is_integer(obj) -> bool: ...
def is_float(obj) -> bool: ...
def is_complex(obj) -> bool: ...
def is_scalar(obj) -> bool: ...
def is_decimal(obj) -> bool: ...
def is_interval(obj) -> bool: ...
def is_list_like(obj) -> bool: ...
def is_number(obj) -> bool: ...
def is_iterator(obj) -> bool: ...
def is_file_like(obj) -> bool: ...
def is_re(obj) -> bool: ...
def is_re_compilable(obj) -> bool: ...
def is_array_like(obj) -> bool: ...
def is_nested_list_like(obj) -> bool: ...
def is_dict_like(obj) -> bool: ...
def is_named_tuple(obj) -> bool: ...
def is_hashable(obj) -> bool: ...
def is_sequence(obj) -> bool: ...
from pandas._libs import lib

is_bool = lib.is_bool
is_integer = lib.is_integer
is_float = lib.is_float
is_complex = lib.is_complex
is_scalar = lib.is_scalar
is_decimal = lib.is_decimal
is_interval = lib.is_interval
is_list_like = lib.is_list_like
is_iterator = lib.is_iterator

def is_number(obj: object) -> bool: ...
def is_file_like(obj: object) -> bool: ...
def is_re(obj: object) -> bool: ...
def is_array_like(obj: object) -> bool: ...
def is_re_compilable(obj: object) -> bool: ...
def is_dict_like(obj: object) -> bool: ...
def is_named_tuple(obj: object) -> bool: ...
def is_hashable(obj: object) -> bool: ...
4 changes: 0 additions & 4 deletions pandas-stubs/core/dtypes/missing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ def notna(obj: Index | list | ArrayLike) -> np.ndarray: ...
def notna(obj: Scalar) -> bool: ...

notnull = notna

def array_equivalent(left, right, strict_nan: bool = ...) -> bool: ...
def na_value_for_dtype(dtype, compat: bool = ...): ...
def remove_na_arraylike(arr): ...
5 changes: 1 addition & 4 deletions pandas-stubs/core/ops/dispatch.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import numpy as np

from pandas.core.dtypes.generic import (
ABCExtensionArray as ABCExtensionArray,
ABCSeries,
)
from pandas.core.dtypes.generic import ABCSeries

def should_extension_dispatch(left: ABCSeries, right) -> bool: ...
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


def check(actual: T, klass: type, dtype: type | None = None, attr: str = "left") -> T:

if not isinstance(actual, klass):
raise RuntimeError(f"Expected type '{klass}' but got '{type(actual)}'")
if dtype is None:
Expand Down
Loading