Skip to content

STYLE: dont use pd api types in tests #39293

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
05d984d
STYLE: remove use in pd.api.dtype in test_ufunc.py (#39203)
nofarmish Jan 17, 2021
2cf8a03
STYLE: remove use in pd.api.dtype in test_integer.py (#39203)
nofarmish Jan 17, 2021
3df6018
STYLE: remove use in pd.api.dtype in doc-string in inference.py (#39203)
nofarmish Jan 17, 2021
258e70c
STYLE: remove use in pd.api.dtype in json/array.py (#39203)
nofarmish Jan 17, 2021
644c9fb
STYLE: remove use in pd.api.dtype in test_floating.py (#39203)
nofarmish Jan 17, 2021
a48fb73
STYLE: remove use in pd.api.dtype in list/array.py (#39203)
nofarmish Jan 17, 2021
8aa77e6
STYLE: remove use in pd.api.dtype in dtype.py (#39203)
nofarmish Jan 17, 2021
3e03fd5
STYLE: remove use in pd.api.dtype in test_bool.py (#39203)
nofarmish Jan 17, 2021
91467ad
STYLE: remove use in pd.api.dtype in reshape.py (#39203)
nofarmish Jan 17, 2021
acea340
STYLE: remove use in pd.api.dtype in arrow/arrays.py (#39203)
nofarmish Jan 17, 2021
058e1ae
STYLE: remove use in pd.api.dtype from doc-string and add import in g…
nofarmish Jan 17, 2021
544d6f8
STYLE: remove use in pd.api.dtype in decimal/array.py (#39203)
nofarmish Jan 17, 2021
5fed74f
STYLE: remove extra line (#39203)
nofarmish Jan 17, 2021
5caa14c
STYLE: run precommit hook to fix import locations (#39203)
nofarmish Jan 17, 2021
555834a
STYLE: change location of import (#39203)
nofarmish Jan 20, 2021
845fccb
STYLE: fix import location after precommit (#39203)
nofarmish Jan 20, 2021
20ddb80
STYLE: add precommit rule (#39203)
nofarmish Jan 20, 2021
eeee8ca
STYLE: add precommit rule - fix typo(#39203)
nofarmish Jan 20, 2021
6a39fac
STYLE: import is_list_like from pandas.api.types (#39203)
nofarmish Jan 20, 2021
8629edd
STYLE: add pandas to precommit hook (#39203)
nofarmish Jan 20, 2021
5cdd952
STYLE: change comment (#39203)
nofarmish Jan 20, 2021
8df1b90
Trigger CI
nofarmish Jan 21, 2021
8fdbb55
Merge branch 'master' into issue-39203-dont-use-pd-api-types-in-tests
nofarm3 Jan 21, 2021
b50e7bf
STYLE: remove use in pd.api.dtype in test_ufunc.py (#39203)
nofarmish Jan 17, 2021
c36241f
STYLE: remove use in pd.api.dtype in test_integer.py (#39203)
nofarmish Jan 17, 2021
475e442
STYLE: remove use in pd.api.dtype in doc-string in inference.py (#39203)
nofarmish Jan 17, 2021
a4c1485
STYLE: remove use in pd.api.dtype in json/array.py (#39203)
nofarmish Jan 17, 2021
29cde03
STYLE: remove use in pd.api.dtype in test_floating.py (#39203)
nofarmish Jan 17, 2021
c444697
STYLE: remove use in pd.api.dtype in list/array.py (#39203)
nofarmish Jan 17, 2021
215db54
STYLE: remove use in pd.api.dtype in dtype.py (#39203)
nofarmish Jan 17, 2021
d18860d
STYLE: remove use in pd.api.dtype in test_bool.py (#39203)
nofarmish Jan 17, 2021
ad1838b
STYLE: remove use in pd.api.dtype in reshape.py (#39203)
nofarmish Jan 17, 2021
68b71f2
STYLE: remove use in pd.api.dtype in arrow/arrays.py (#39203)
nofarmish Jan 17, 2021
ce931ed
STYLE: remove use in pd.api.dtype from doc-string and add import in g…
nofarmish Jan 17, 2021
99440e3
STYLE: remove use in pd.api.dtype in decimal/array.py (#39203)
nofarmish Jan 17, 2021
f348c30
STYLE: remove extra line (#39203)
nofarmish Jan 17, 2021
843e214
STYLE: run precommit hook to fix import locations (#39203)
nofarmish Jan 17, 2021
1df8858
STYLE: change location of import (#39203)
nofarmish Jan 20, 2021
5cb207b
STYLE: fix import location after precommit (#39203)
nofarmish Jan 20, 2021
f85eddd
STYLE: add precommit rule (#39203)
nofarmish Jan 20, 2021
99c5a84
STYLE: add precommit rule - fix typo(#39203)
nofarmish Jan 20, 2021
5b8596c
STYLE: import is_list_like from pandas.api.types (#39203)
nofarmish Jan 20, 2021
c33b7d0
STYLE: add pandas to precommit hook (#39203)
nofarmish Jan 20, 2021
4fb1ec5
STYLE: change comment (#39203)
nofarmish Jan 20, 2021
c56a2bf
Revert "CI: Skip numpy dev failing tests (#39090)" (#39225)
phofl Jan 17, 2021
2393140
Added docs for the change of behavior of isin (#39064)
omarafifii Jan 17, 2021
33c0015
ENH: Styler tooltips feature (#35643)
attack68 Jan 17, 2021
3b3bcf9
BUG: Placeholders not being filled on docstrings (#39139)
MicaelJarniac Jan 17, 2021
dfd705f
CI: pre-commit fixup (#39232)
simonjayhawkins Jan 17, 2021
f278480
DOC: 1.2.1 release date (#39233)
simonjayhawkins Jan 17, 2021
0acc13a
DOC: clean-up of v1.2.1 whatsnew (#39246)
jorisvandenbossche Jan 18, 2021
e35866c
Revert "Inconsistent indexes for tick label plotting (#28733)" (#39235)
simonjayhawkins Jan 18, 2021
23f12f2
REGR: to_stata tried to remove file before closing it (#39202)
twoertwein Jan 18, 2021
263f50a
DOC: keep color for note admonitions in sphinx theme (#39256)
jorisvandenbossche Jan 19, 2021
f3cffb9
REGR: codecs.open() is always opened in text mode (#39253)
twoertwein Jan 19, 2021
5bc2006
DEPR: EWM.vol (#39220)
mroeschke Jan 19, 2021
4d50974
REGR: fix numpy accumulate ufuncs for DataFrame (#39260)
jorisvandenbossche Jan 19, 2021
8fb52ae
CI: skip checking freq on flaky pytables test (#39262)
jbrockmendel Jan 19, 2021
be6c41c
CLN: remove pd import in pandas/core/computation (#39268)
ivanovmg Jan 19, 2021
fb3d431
REF: roll IntBlock, BoolBlock, ComplexBlock into NumericBlock (#39236)
jbrockmendel Jan 19, 2021
4aff972
CLN: remove unused axis kwarg from Block.putmask (#39238)
jbrockmendel Jan 19, 2021
77b3950
CLN: use getvalue instead of seek(0)+read() (#39213)
twoertwein Jan 19, 2021
5dc9e15
REF: extract classes in pandas/core/describe.py (#39186)
ivanovmg Jan 19, 2021
ad32e00
BUG: DataFrame.apply axis=1 for str ops with no axis argument (#39212)
rhshadrach Jan 19, 2021
171112e
TST GH26807 Break up test_strings (#39215)
moink Jan 19, 2021
594724a
BUG: GroupBy.idxmax/idxmin with EA dtypes (#38733)
jbrockmendel Jan 19, 2021
0ec3ccc
API/BUG: treat different UTC tzinfos as equal (#39216)
jbrockmendel Jan 19, 2021
de3ca00
CLN refactor rest of core (#37586)
MarcoGorelli Jan 20, 2021
85e4004
fix series.isin slow issue with Dtype IntegerArray (#38379)
tushushu Jan 20, 2021
05d82ac
DEPR: raise deprecation warning in numpy ufuncs on DataFrames if not …
jorisvandenbossche Jan 20, 2021
f9c6977
DOC: Start v1.2.2 release notes (#39234)
simonjayhawkins Jan 20, 2021
b8105bc
ENH: cast instead of raise for IntervalIndex setops with differnet cl…
jbrockmendel Jan 20, 2021
ad4dfff
REF: split describe categorical function (#39287)
ivanovmg Jan 20, 2021
62e499b
TST: Add test to ensure DF describe does not throw an error (#32409) …
luckyvs1 Jan 20, 2021
6abf551
REF: share PeriodArray.asfreq with Period.asfreq (#39277)
jbrockmendel Jan 20, 2021
75a485c
ENH: Period comparisons with mismatched freq use py3 behavior (#39274)
jbrockmendel Jan 20, 2021
d61a518
PERF: cythonize kendall correlation (#39132)
lithomas1 Jan 20, 2021
794e32b
ENH: Make Timestamp implementation bounds match DatetimeArray/Datetim…
jbrockmendel Jan 20, 2021
a926d4b
CLN: consistently put '|' at start of line in pygrep hooks #39301 (#3…
gustavocmaciel Jan 20, 2021
9b150ed
BUG: date_range hitting iNaT (#39308)
jbrockmendel Jan 21, 2021
f53eab8
Merge remote-tracking branch 'origin/issue-39203-dont-use-pd-api-type…
nofarmish Jan 21, 2021
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ repos:
pandas/tests/io/excel/test_writers\.py
|pandas/tests/io/pytables/common\.py
|pandas/tests/io/pytables/test_store\.py$
- id: no-pandas-api-types
name: Check code for instances of pd.api.types
entry: (pd|pandas)\.api\.types\.
language: pygrep
types: [python]
files: ^pandas/tests/
- repo: https://github.com/asottile/yesqa
rev: v1.2.2
hooks:
Expand Down
3 changes: 2 additions & 1 deletion asv_bench/benchmarks/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
from pandas import DataFrame, MultiIndex, date_range, melt, wide_to_long
from pandas.api.types import CategoricalDtype


class Melt:
Expand Down Expand Up @@ -196,7 +197,7 @@ def setup(self):
categories = list(string.ascii_letters[:12])
s = pd.Series(
np.random.choice(categories, size=1000000),
dtype=pd.api.types.CategoricalDtype(categories),
dtype=CategoricalDtype(categories),
)
self.s = s

Expand Down
11 changes: 6 additions & 5 deletions pandas/core/dtypes/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ def is_number(obj) -> bool:

Examples
--------
>>> pd.api.types.is_number(1)
>>> from pandas.api.types import is_number
>>> is_number(1)
True
>>> pd.api.types.is_number(7.15)
>>> is_number(7.15)
True

Booleans are valid because they are int subclass.

>>> pd.api.types.is_number(False)
>>> is_number(False)
True

>>> pd.api.types.is_number("foo")
>>> is_number("foo")
False
>>> pd.api.types.is_number("5")
>>> is_number("5")
False
"""
return isinstance(obj, (Number, np.number))
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5813,7 +5813,8 @@ def astype(

Convert to ordered categorical type with custom ordering:

>>> cat_dtype = pd.api.types.CategoricalDtype(
>>> from pandas.api.types import CategoricalDtype
>>> cat_dtype = CategoricalDtype(
... categories=[2, 1], ordered=True)
>>> ser.astype(cat_dtype)
0 1
Expand Down
1 change: 1 addition & 0 deletions pandas/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Public testing utility functions.
"""


from pandas._testing import (
assert_extension_array_equal,
assert_frame_equal,
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/arrow/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
register_extension_dtype,
take,
)
from pandas.api.types import is_scalar
from pandas.core.arraylike import OpsMixin


Expand Down Expand Up @@ -89,7 +90,7 @@ def __repr__(self):
return f"{type(self).__name__}({repr(self._data)})"

def __getitem__(self, item):
if pd.api.types.is_scalar(item):
if is_scalar(item):
return self._data.to_pandas()[item]
else:
vals = self._data.to_pandas()[item]
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/arrow/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pandas as pd
import pandas._testing as tm
from pandas.api.types import is_bool_dtype
from pandas.tests.extension import base

pytest.importorskip("pyarrow", minversion="0.13.0")
Expand Down Expand Up @@ -89,7 +90,7 @@ class TestReduceBoolean(base.BaseBooleanReduceTests):


def test_is_bool_dtype(data):
assert pd.api.types.is_bool_dtype(data)
assert is_bool_dtype(data)
assert pd.core.common.is_bool_indexer(data)
s = pd.Series(range(len(data)))
result = s[data]
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/extension/base/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import pandas as pd
from pandas.api.types import is_object_dtype, is_string_dtype

from .base import BaseExtensionTests

Expand Down Expand Up @@ -41,10 +42,10 @@ def test_is_dtype_other_input(self, dtype):
assert dtype.is_dtype([1, 2, 3]) is False

def test_is_not_string_type(self, dtype):
return not pd.api.types.is_string_dtype(dtype)
return not is_string_dtype(dtype)

def test_is_not_object_type(self, dtype):
return not pd.api.types.is_object_dtype(dtype)
return not is_object_dtype(dtype)

def test_eq_with_str(self, dtype):
assert dtype == dtype.name
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import numpy as np

from pandas.core.dtypes.base import ExtensionDtype
from pandas.core.dtypes.common import is_dtype_equal, is_list_like, pandas_dtype
from pandas.core.dtypes.common import is_dtype_equal, pandas_dtype

import pandas as pd
from pandas.api.extensions import no_default, register_extension_dtype
from pandas.api.types import is_list_like, is_scalar
from pandas.core.arraylike import OpsMixin
from pandas.core.arrays import ExtensionArray, ExtensionScalarOpsMixin
from pandas.core.indexers import check_array_indexer
Expand Down Expand Up @@ -142,8 +143,8 @@ def astype(self, dtype, copy=True):
return super().astype(dtype, copy=copy)

def __setitem__(self, key, value):
if pd.api.types.is_list_like(value):
if pd.api.types.is_scalar(key):
if is_list_like(value):
if is_scalar(key):
raise ValueError("setting an array element with a sequence.")
value = [decimal.Decimal(v) for v in value]
else:
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import pandas as pd
from pandas.api.extensions import ExtensionArray, ExtensionDtype
from pandas.api.types import is_bool_dtype


class JSONDtype(ExtensionDtype):
Expand Down Expand Up @@ -80,7 +81,7 @@ def __getitem__(self, item):
return type(self)(self.data[item])
else:
item = pd.api.indexers.check_array_indexer(self, item)
if pd.api.types.is_bool_dtype(item.dtype):
if is_bool_dtype(item.dtype):
return self._from_sequence([x for x, m in zip(self, item) if m])
# integer
return type(self)([self.data[i] for i in item])
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/extension/list/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pandas.core.dtypes.base import ExtensionDtype

import pandas as pd
from pandas.api.types import is_object_dtype, is_string_dtype
from pandas.core.arrays import ExtensionArray


Expand Down Expand Up @@ -104,9 +105,7 @@ def astype(self, dtype, copy=True):
if copy:
return self.copy()
return self
elif pd.api.types.is_string_dtype(dtype) and not pd.api.types.is_object_dtype(
dtype
):
elif is_string_dtype(dtype) and not is_object_dtype(dtype):
# numpy has problems with astype(str) for nested elements
return np.array([str(x) for x in self.data], dtype=dtype)
return np.array(self.data, dtype=dtype, copy=copy)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/test_floating.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import pandas as pd
import pandas._testing as tm
from pandas.api.types import is_float_dtype
from pandas.core.arrays.floating import Float32Dtype, Float64Dtype
from pandas.tests.extension import base

Expand Down Expand Up @@ -101,7 +102,7 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
if (
hasattr(other, "dtype")
and not is_extension_array_dtype(other.dtype)
and pd.api.types.is_float_dtype(other.dtype)
and is_float_dtype(other.dtype)
):
# other is np.float64 and would therefore always result in
# upcasting, so keeping other as same numpy_dtype
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/extension/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
import numpy as np
import pytest

from pandas.core.dtypes.common import is_extension_array_dtype

import pandas as pd
import pandas._testing as tm
from pandas.api.types import is_extension_array_dtype, is_integer_dtype
from pandas.core.arrays.integer import (
Int8Dtype,
Int16Dtype,
Expand Down Expand Up @@ -119,7 +118,7 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
if (
hasattr(other, "dtype")
and not is_extension_array_dtype(other.dtype)
and pd.api.types.is_integer_dtype(other.dtype)
and is_integer_dtype(other.dtype)
):
# other is np.int64 and would therefore always result in
# upcasting, so keeping other as same numpy_dtype
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/frame/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
import pandas._testing as tm
from pandas.api.types import is_extension_array_dtype

dtypes = [
"int64",
Expand All @@ -28,7 +29,7 @@ def test_unary_unary(dtype):
@pytest.mark.parametrize("dtype", dtypes)
def test_unary_binary(request, dtype):
# unary input, binary output
if pd.api.types.is_extension_array_dtype(dtype) or isinstance(dtype, dict):
if is_extension_array_dtype(dtype) or isinstance(dtype, dict):
request.node.add_marker(
pytest.mark.xfail(
reason="Extension / mixed with multiple outputs not implemented."
Expand Down Expand Up @@ -63,9 +64,9 @@ def test_binary_input_dispatch_binop(dtype):
@pytest.mark.parametrize("dtype_b", dtypes)
def test_binary_input_aligns_columns(request, dtype_a, dtype_b):
if (
pd.api.types.is_extension_array_dtype(dtype_a)
is_extension_array_dtype(dtype_a)
or isinstance(dtype_a, dict)
or pd.api.types.is_extension_array_dtype(dtype_b)
or is_extension_array_dtype(dtype_b)
or isinstance(dtype_b, dict)
):
request.node.add_marker(
Expand Down Expand Up @@ -98,7 +99,7 @@ def test_binary_input_aligns_columns(request, dtype_a, dtype_b):

@pytest.mark.parametrize("dtype", dtypes)
def test_binary_input_aligns_index(request, dtype):
if pd.api.types.is_extension_array_dtype(dtype) or isinstance(dtype, dict):
if is_extension_array_dtype(dtype) or isinstance(dtype, dict):
request.node.add_marker(
pytest.mark.xfail(
reason="Extension / mixed with multiple inputs not implemented."
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/multiindex/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_loc_getitem_int_slice(self):
def test_loc_getitem_nested_indexer(self, indexer_type_1, indexer_type_2):
# GH #19686
# .loc should work with nested indexers which can be
# any list-like objects (see `pandas.api.types.is_list_like`) or slices
# any list-like objects (see `is_list_like` (`pandas.api.types`)) or slices

def convert_nested_indexer(indexer_type, keys):
if indexer_type == np.ndarray:
Expand Down