Skip to content

CLN: Consistent imports - linting rules #29318

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
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
# Check for imports from pandas.core.common instead of `import pandas.core.common as com`
# Check for imports from collections.abc instead of `from collections import abc`
MSG='Check for non-standard imports' ; echo $MSG
invgrep -R --include="*.py*" -E "from pandas.core.common import " pandas
invgrep -R --include="*.py*" -E "from collections.abc import " pandas
invgrep -R --include="*.py*" -E "from numpy import nan " pandas
invgrep -R --include="*.py*" -E "from pandas.core.common import" pandas
invgrep -R --include="*.py*" -E "from pandas.core import common" pandas
Copy link
Contributor Author

@SaturnFromTitan SaturnFromTitan Nov 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the pattern from pandas.core import common as com is used in the code base as an alternative to the desired import pandas.core.common as com. Therefore I fixed the existing cases (not a breaking change) and added this linting rule here. Let me know if that's fine with you or if this should rather go into a separate PR 🙂✌️

invgrep -R --include="*.py*" -E "from collections.abc import" pandas
invgrep -R --include="*.py*" -E "from numpy import nan" pandas
Copy link
Contributor Author

@SaturnFromTitan SaturnFromTitan Nov 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the trailing spaces in the import strings to make them more robust to multi-line imports.
Also for the from numpy import nan import they didn't make sense at all. It doesn't seem to be valid syntax anymore though, so it doesn't require any additional clean up


# Checks for test suite
# Check for imports from pandas.util.testing instead of `import pandas.util.testing as tm`
invgrep -R --include="*.py*" -E "from pandas.util.testing import" pandas/tests
invgrep -R --include="*.py*" -E "from pandas.util import testing as tm" pandas/tests
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check for use of exec' ; echo $MSG
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from pandas.core.dtypes.generic import ABCIndex, ABCIndexClass, ABCSeries
from pandas.core.dtypes.missing import isna, na_value_for_dtype

from pandas.core import common as com
import pandas.core.common as com
from pandas.core.construction import array, extract_array
from pandas.core.indexers import validate_indices

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np

import pandas as pd
from pandas.core import common as com
import pandas.core.common as com
from pandas.core.computation.common import (
_BACKTICK_QUOTED_STRING,
_remove_spaces_column_name,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
pandas_dtype,
)

from pandas.core import common as com
from pandas.core.accessor import delegate_names
from pandas.core.algorithms import unique1d
from pandas.core.arrays.period import PeriodArray, period_array, validate_dtype_freq
from pandas.core.base import _shared_docs
import pandas.core.common as com
import pandas.core.indexes.base as ibase
from pandas.core.indexes.base import _index_shared_docs, ensure_index
from pandas.core.indexes.datetimelike import (
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import numpy as np

from pandas import DataFrame, Index, MultiIndex, Series
from pandas.core import common as com
from pandas.core.arrays.categorical import (
_factorize_from_iterable,
_factorize_from_iterables,
)
import pandas.core.common as com
from pandas.core.generic import NDFrame
from pandas.core.index import (
_all_indexes_same,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pandas.core.dtypes.common import is_list_like

from pandas.core import common as com
import pandas.core.common as com


def cartesian_product(X):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

from pandas import DataFrame, MultiIndex, Series
from pandas.core import common as com
import pandas.core.common as com
import pandas.util.testing as tm


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_chaining_and_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pandas as pd
from pandas import DataFrame, Series, Timestamp, date_range, option_context
from pandas.core import common as com
import pandas.core.common as com
import pandas.util.testing as tm


Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import pandas as pd
from pandas import Series, Timestamp
from pandas.core import common as com, ops
from pandas.core import ops
import pandas.core.common as com


def test_get_callable_name():
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

from pandas import DataFrame, MultiIndex, Series, array, concat, merge
from pandas.core import common as com
import pandas.core.common as com
from pandas.core.sorting import (
decons_group_index,
get_group_index,
Expand Down