Skip to content

CI: update to isort 5 (#35134) #35163

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
wants to merge 7 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 10 additions & 4 deletions asv_bench/benchmarks/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
import numpy as np

import pandas as pd
from pandas import DataFrame, Series, Timestamp, date_range, to_timedelta
import pandas._testing as tm
from pandas import (
DataFrame,
Series,
Timestamp,
_testing as tm,
date_range,
to_timedelta,
)
from pandas.core.algorithms import checked_add_with_arr

from .pandas_vb_common import numeric_dtypes

try:
import pandas.core.computation.expressions as expr
from pandas.core.computation import expressions as expr
except ImportError:
import pandas.computation.expressions as expr
from pandas.computation import expressions as expr
try:
import pandas.tseries.holiday
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pandas as pd

try:
import pandas.core.computation.expressions as expr
from pandas.core.computation import expressions as expr
except ImportError:
import pandas.computation.expressions as expr
from pandas.computation import expressions as expr


class Eval:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/frame_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .pandas_vb_common import tm

try:
from pandas.tseries.offsets import Nano, Hour
from pandas.tseries.offsets import Hour, Nano
except ImportError:
# For compatibility with older versions
from pandas.core.datetools import * # noqa
Expand Down
8 changes: 4 additions & 4 deletions asv_bench/benchmarks/gil.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

try:
from pandas import (
rolling_median,
rolling_kurt,
rolling_max,
rolling_mean,
rolling_median,
rolling_min,
rolling_max,
rolling_var,
rolling_skew,
rolling_kurt,
rolling_std,
rolling_var,
)

have_rolling_methods = True
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

try:
from pandas._libs.tslibs.parsing import (
concat_date_cols,
_does_string_look_like_datetime,
concat_date_cols,
)
except ImportError:
# Avoid whole benchmark suite import failure on asv (currently 0.4)
Expand Down
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/pandas_vb_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

# Compatibility import for the testing module
try:
import pandas._testing as tm # noqa
from pandas import _testing as tm # noqa
except ImportError:
import pandas.util.testing as tm # noqa
from pandas.util import testing as tm # noqa


numeric_dtypes = [
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/tslibs/normalize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
try:
from pandas._libs.tslibs import normalize_i8_timestamps, is_date_array_normalized
from pandas._libs.tslibs import is_date_array_normalized, normalize_i8_timestamps
except ImportError:
from pandas._libs.tslibs.conversion import (
normalize_i8_timestamps,
Expand Down
2 changes: 1 addition & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then

# Imports - Check formatting using isort see setup.cfg for settings
MSG='Check import format using isort' ; echo $MSG
ISORT_CMD="isort --quiet --recursive --check-only pandas asv_bench scripts"
ISORT_CMD="isort --quiet --check-only pandas asv_bench scripts"
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
eval $ISORT_CMD | awk '{print "##[error]" $0}'; RET=$(($RET + ${PIPESTATUS[0]}))
else
Expand Down
2 changes: 1 addition & 1 deletion doc/source/development/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ Imports are alphabetically sorted within these sections.

As part of :ref:`Continuous Integration <contributing.ci>` checks we run::

isort --recursive --check-only pandas
isort --check-only pandas

to check that imports are correctly formatted as per the `setup.cfg`.

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
- flake8<3.8.0 # temporary pin, GH#34150
- flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions
- flake8-rst>=0.6.0,<=0.7.0 # linting of code blocks in rst files
- isort=4.3.21 # check that imports are in the right order
- isort=5.1.1 # check that imports are in the right order
- mypy=0.730
- pycodestyle # used by flake8

Expand Down
5 changes: 2 additions & 3 deletions pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
which can save developers some typing, see the docstring.

"""

from collections import namedtuple
from contextlib import ContextDecorator, contextmanager
import re
Expand Down Expand Up @@ -442,8 +441,8 @@ def register_option(
ValueError if `validator` is specified and `defval` is not a valid value.

"""
import tokenize
import keyword
import tokenize

key = key.lower()

Expand Down Expand Up @@ -660,8 +659,8 @@ def _build_option_description(k: str) -> str:

def pp_options_list(keys: Iterable[str], width=80, _print: bool = False):
""" Builds a concise listing of available options, grouped by prefix """
from textwrap import wrap
from itertools import groupby
from textwrap import wrap

def pp(name: str, ks: Iterable[str]) -> List[str]:
pfx = "- " + name + ".[" if name else ""
Expand Down
14 changes: 7 additions & 7 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import cython
from cython import Py_ssize_t

from libc.stdlib cimport malloc, free
from libc.string cimport memmove
from libc.math cimport fabs, sqrt
from libc.stdlib cimport free, malloc
from libc.string cimport memmove

import numpy as np

cimport numpy as cnp
from numpy cimport (
NPY_FLOAT32,
Expand All @@ -31,12 +32,11 @@ from numpy cimport (
uint32_t,
uint64_t,
)
cnp.import_array()

cnp.import_array()

cimport pandas._libs.util as util
from pandas._libs.util cimport numeric, get_nat

from pandas._libs cimport util as util
from pandas._libs.khash cimport (
kh_destroy_int64,
kh_get_int64,
Expand All @@ -46,9 +46,9 @@ from pandas._libs.khash cimport (
kh_resize_int64,
khiter_t,
)
from pandas._libs.util cimport get_nat, numeric


import pandas._libs.missing as missing
from pandas._libs import missing as missing

cdef:
float64_t FP_ERR = 1e-13
Expand Down
48 changes: 36 additions & 12 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
import cython
from cython import Py_ssize_t
from cython cimport floating

from libc.stdlib cimport malloc, free
from cython cimport floating
from libc.stdlib cimport free, malloc

import numpy as np

cimport numpy as cnp
from numpy cimport (ndarray,
int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
uint32_t, uint64_t, float32_t, float64_t, complex64_t, complex128_t)
from numpy cimport (
complex64_t,
complex128_t,
float32_t,
float64_t,
int8_t,
int16_t,
int32_t,
int64_t,
ndarray,
uint8_t,
uint16_t,
uint32_t,
uint64_t,
)
from numpy.math cimport NAN
cnp.import_array()

from pandas._libs.util cimport numeric, get_nat
cnp.import_array()

from pandas._libs.algos cimport (swap, TiebreakEnumType, TIEBREAK_AVERAGE,
TIEBREAK_MIN, TIEBREAK_MAX, TIEBREAK_FIRST,
TIEBREAK_DENSE)
from pandas._libs.algos import (take_2d_axis1_float64_float64,
groupsort_indexer, tiebreakers)
from pandas._libs.algos cimport (
TIEBREAK_AVERAGE,
TIEBREAK_DENSE,
TIEBREAK_FIRST,
TIEBREAK_MAX,
TIEBREAK_MIN,
TiebreakEnumType,
swap,
)
from pandas._libs.util cimport get_nat, numeric

from pandas._libs.algos import (
groupsort_indexer,
take_2d_axis1_float64_float64,
tiebreakers,
)

from pandas._libs.missing cimport checknull


cdef int64_t NPY_NAT = get_nat()
_int64_max = np.iinfo(np.int64).max

Expand Down
8 changes: 5 additions & 3 deletions pandas/_libs/hashing.pyx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Translated from the reference implementation
# at https://github.com/veorq/SipHash

import cython
from libc.stdlib cimport malloc, free

from libc.stdlib cimport free, malloc

import numpy as np
from numpy cimport ndarray, uint8_t, uint32_t, uint64_t, import_array

from numpy cimport import_array, ndarray, uint8_t, uint32_t, uint64_t

import_array()

from pandas._libs.util cimport is_nan
Expand Down
75 changes: 36 additions & 39 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
@@ -1,60 +1,57 @@
cimport cython

from cpython.ref cimport PyObject, Py_INCREF
from cpython.mem cimport PyMem_Malloc, PyMem_Free

from libc.stdlib cimport malloc, free
from cpython.mem cimport PyMem_Free, PyMem_Malloc
from cpython.ref cimport Py_INCREF, PyObject
from libc.stdlib cimport free, malloc

import numpy as np

cimport numpy as cnp
from numpy cimport ndarray, uint8_t, uint32_t, float64_t
from numpy cimport float64_t, ndarray, uint8_t, uint32_t
from numpy.math cimport NAN

cnp.import_array()


from pandas._libs cimport util
from pandas._libs.khash cimport (
khiter_t,
kh_str_t,
kh_init_str,
kh_put_str,
kh_exist_str,
kh_get_str,
kh_destroy_str,
kh_resize_str,
kh_put_strbox,
kh_get_strbox,
kh_init_strbox,
kh_int64_t,
kh_init_int64,
kh_resize_int64,
kh_destroy_float64,
kh_destroy_int64,
kh_get_int64,
kh_destroy_pymap,
kh_destroy_str,
kh_destroy_uint64,
kh_exist_float64,
kh_exist_int64,
kh_put_int64,
kh_exist_pymap,
kh_exist_str,
kh_exist_uint64,
kh_float64_t,
kh_exist_float64,
kh_put_float64,
kh_init_float64,
kh_get_float64,
kh_destroy_float64,
kh_resize_float64,
kh_resize_uint64,
kh_exist_uint64,
kh_destroy_uint64,
kh_put_uint64,
kh_get_int64,
kh_get_pymap,
kh_get_str,
kh_get_strbox,
kh_get_uint64,
kh_init_uint64,
kh_destroy_pymap,
kh_exist_pymap,
kh_init_float64,
kh_init_int64,
kh_init_pymap,
kh_get_pymap,
kh_init_str,
kh_init_strbox,
kh_init_uint64,
kh_int64_t,
kh_put_float64,
kh_put_int64,
kh_put_pymap,
kh_put_str,
kh_put_strbox,
kh_put_uint64,
kh_resize_float64,
kh_resize_int64,
kh_resize_pymap,
kh_resize_str,
kh_resize_uint64,
kh_str_t,
khiter_t,
)


from pandas._libs cimport util

from pandas._libs.missing cimport checknull


Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings

import numpy as np

cimport numpy as cnp
from numpy cimport (
float32_t,
Expand All @@ -16,17 +17,16 @@ from numpy cimport (
uint32_t,
uint64_t,
)

cnp.import_array()


from pandas._libs cimport util

from pandas._libs.hashtable cimport HashTable
from pandas._libs.tslibs.nattype cimport c_NaT as NaT
from pandas._libs.tslibs.period cimport is_period_object
from pandas._libs.tslibs.timestamps cimport _Timestamp
from pandas._libs.tslibs.timedeltas cimport _Timedelta

from pandas._libs.hashtable cimport HashTable
from pandas._libs.tslibs.timestamps cimport _Timestamp

from pandas._libs import algos, hashtable as _hash
from pandas._libs.missing import checknull
Expand Down
Loading