Skip to content

STYLE: dont' use pd.api.types anywhere in tests #39203

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

Closed
jreback opened this issue Jan 16, 2021 · 10 comments · Fixed by #39293
Closed

STYLE: dont' use pd.api.types anywhere in tests #39203

jreback opened this issue Jan 16, 2021 · 10 comments · Fixed by #39293
Assignees
Labels
Code Style Code style, linting, code_checks good first issue
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Jan 16, 2021

example here: https://github.com/pandas-dev/pandas/pull/37367/files#diff-69c698518ca64a05f8b137ff9bb5445ce9fd21139b396e9b0d4ce7338b2a3984R132

we should just ban this with a precommit style rule (and import things directly). the doc-strings also should be updated to do the import once.

grep -r pd.api.types ~/pandas-dev/pandas
/home/jreback/pandas-dev/pandas/_libs/lib.pyx:    >>> pd.api.types.is_scalar(dt)
/home/jreback/pandas-dev/pandas/_libs/lib.pyx:    >>> pd.api.types.is_scalar([2, 3])
/home/jreback/pandas-dev/pandas/_libs/lib.pyx:    >>> pd.api.types.is_scalar({0: 1, 2: 3})
/home/jreback/pandas-dev/pandas/_libs/lib.pyx:    >>> pd.api.types.is_scalar((0, 2))
/home/jreback/pandas-dev/pandas/_libs/lib.pyx:    >>> pd.api.types.is_scalar(Fraction(3, 5))
/home/jreback/pandas-dev/pandas/tests/frame/test_ufunc.py:    if pd.api.types.is_extension_array_dtype(dtype) or isinstance(dtype, dict):
/home/jreback/pandas-dev/pandas/tests/frame/test_ufunc.py:        pd.api.types.is_extension_array_dtype(dtype_a)
/home/jreback/pandas-dev/pandas/tests/frame/test_ufunc.py:        or pd.api.types.is_extension_array_dtype(dtype_b)
/home/jreback/pandas-dev/pandas/tests/frame/test_ufunc.py:    if pd.api.types.is_extension_array_dtype(dtype) or isinstance(dtype, dict):
/home/jreback/pandas-dev/pandas/tests/extension/base/dtype.py:        return not pd.api.types.is_string_dtype(dtype)
/home/jreback/pandas-dev/pandas/tests/extension/base/dtype.py:        return not pd.api.types.is_object_dtype(dtype)
/home/jreback/pandas-dev/pandas/tests/extension/arrow/arrays.py:        if pd.api.types.is_scalar(item):
/home/jreback/pandas-dev/pandas/tests/extension/arrow/test_bool.py:    assert pd.api.types.is_bool_dtype(data)
/home/jreback/pandas-dev/pandas/tests/extension/json/array.py:            if pd.api.types.is_bool_dtype(item.dtype):
/home/jreback/pandas-dev/pandas/tests/extension/decimal/array.py:        if pd.api.types.is_list_like(value):
/home/jreback/pandas-dev/pandas/tests/extension/decimal/array.py:            if pd.api.types.is_scalar(key):
/home/jreback/pandas-dev/pandas/tests/extension/list/array.py:        elif pd.api.types.is_string_dtype(dtype) and not pd.api.types.is_object_dtype(
/home/jreback/pandas-dev/pandas/tests/extension/test_integer.py:                and pd.api.types.is_integer_dtype(other.dtype)
/home/jreback/pandas-dev/pandas/tests/extension/test_floating.py:                and pd.api.types.is_float_dtype(other.dtype)
/home/jreback/pandas-dev/pandas/core/dtypes/inference.py:    >>> pd.api.types.is_number(1)
/home/jreback/pandas-dev/pandas/core/dtypes/inference.py:    >>> pd.api.types.is_number(7.15)
/home/jreback/pandas-dev/pandas/core/dtypes/inference.py:    >>> pd.api.types.is_number(False)
/home/jreback/pandas-dev/pandas/core/dtypes/inference.py:    >>> pd.api.types.is_number("foo")
/home/jreback/pandas-dev/pandas/core/dtypes/inference.py:    >>> pd.api.types.is_number("5")
/home/jreback/pandas-dev/pandas/core/generic.py:        >>> cat_dtype = pd.api.types.CategoricalDtype(
@jreback jreback added Code Style Code style, linting, code_checks good first issue labels Jan 16, 2021
@jreback jreback added this to the Contributions Welcome milestone Jan 16, 2021
@nofarm3
Copy link
Contributor

nofarm3 commented Jan 16, 2021

Hi @jreback!

To make sure I get this right:

  1. Change it to be:
    from pd.api.types import is_number
    and then just use it in the test.
  2. add a precommit rule

@nofarm3
Copy link
Contributor

nofarm3 commented Jan 16, 2021

take

@MarcoGorelli
Copy link
Member

Hi @nofarm3 - I haven't tried this yet but I think you'll need from pandas.api.types import ... (rather than from pd.api.types import ...) - feel free to reach out if you want/need help with anything!

@nofarm3
Copy link
Contributor

nofarm3 commented Jan 16, 2021

Thanks @MarcoGorelli !

@jorisvandenbossche
Copy link
Member

the doc-strings also should be updated to do the import once.

How do you want the docstrings changed?
Note that those are public functions, and thus need to be documented using their public import (which is pd.api.types)

In addition, IMO we should keep all occurrences in tests/extension as is (or at least the ones in the array classes). Those tests are meant for external projects to use and adapt, and thus should use public APIs to the extent possible.

@jreback
Copy link
Contributor Author

jreback commented Jan 16, 2021

the request is to simply import infer_dtype rather than use the long form

@jreback
Copy link
Contributor Author

jreback commented Jan 16, 2021

having a one off is -1

@nofarm3
Copy link
Contributor

nofarm3 commented Jan 16, 2021

@jreback
I want to make sure I fix it the way you expect (this is my first time):

For example:
if pd.api.types.is_integer_dtype(other.dtype):

I'll change it to be:

from pandas._libs import lib
if lib.infer_dtype(other.dtype) == "integer":

Or

from pandas.api.types import is_integer_dtype
if is_integer_dtype(other.dtype):

I guess the first option is correct, am I right?
Thanks

@MarcoGorelli
Copy link
Member

@nofarm3 the fastest way to get feedback is usually to just open a pull request, even if you're not sure it's correct, reviewers can make suggestions there

@jreback
Copy link
Contributor Author

jreback commented Jan 16, 2021

pls use the public api (2nd way)

nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 17, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 17, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 17, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 20, 2021
@simonjayhawkins simonjayhawkins modified the milestones: Contributions Welcome, 1.3 Jan 20, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 20, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 20, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 20, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 20, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
nofarm3 pushed a commit to nofarm3/pandas that referenced this issue Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants