-
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
CLN: trying isort-dev #32489
CLN: trying isort-dev #32489
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,29 @@ from collections import abc | |
from decimal import Decimal | ||
from fractions import Fraction | ||
from numbers import Number | ||
|
||
import sys | ||
|
||
import cython | ||
from cython import Py_ssize_t | ||
|
||
from cpython.object cimport PyObject_RichCompareBool, Py_EQ | ||
from cpython.ref cimport Py_INCREF | ||
from cpython.tuple cimport PyTuple_SET_ITEM, PyTuple_New | ||
from cpython.iterator cimport PyIter_Check | ||
from cpython.sequence cimport PySequence_Check | ||
from cpython.number cimport PyNumber_Check | ||
|
||
from cpython.datetime cimport ( | ||
PyDateTime_Check, | ||
PyDate_Check, | ||
PyTime_Check, | ||
PyDelta_Check, | ||
PyDateTime_Check, | ||
PyDateTime_IMPORT, | ||
PyDelta_Check, | ||
PyTime_Check, | ||
) | ||
from cpython.iterator cimport PyIter_Check | ||
from cpython.number cimport PyNumber_Check | ||
from cpython.object cimport Py_EQ, PyObject_RichCompareBool | ||
from cpython.ref cimport Py_INCREF | ||
from cpython.sequence cimport PySequence_Check | ||
from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM | ||
|
||
PyDateTime_IMPORT | ||
|
||
import numpy as np | ||
|
||
cimport numpy as cnp | ||
from numpy cimport ( | ||
NPY_OBJECT, | ||
|
@@ -42,6 +42,7 @@ from numpy cimport ( | |
uint8_t, | ||
uint64_t, | ||
) | ||
|
||
cnp.import_array() | ||
|
||
cdef extern from "numpy/arrayobject.h": | ||
|
@@ -65,24 +66,23 @@ cdef extern from "numpy/arrayobject.h": | |
cdef extern from "src/parse_helper.h": | ||
int floatify(object, float64_t *result, int *maybe_int) except -1 | ||
|
||
cimport pandas._libs.util as util | ||
from pandas._libs.util cimport is_nan, UINT64_MAX, INT64_MAX, INT64_MIN | ||
from pandas._libs cimport util | ||
from pandas._libs.util cimport INT64_MAX, INT64_MIN, UINT64_MAX, is_nan | ||
|
||
from pandas._libs.tslib import array_to_datetime | ||
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT | ||
from pandas._libs.tslibs.conversion cimport convert_to_tsobject | ||
from pandas._libs.tslibs.timedeltas cimport convert_to_timedelta64 | ||
from pandas._libs.tslibs.timezones cimport get_timezone, tz_compare | ||
|
||
from pandas._libs.missing cimport ( | ||
C_NA, | ||
checknull, | ||
isnaobj, | ||
is_null_datetime64, | ||
is_null_timedelta64, | ||
is_null_period, | ||
C_NA, | ||
is_null_timedelta64, | ||
isnaobj, | ||
) | ||
|
||
from pandas._libs.tslibs.conversion cimport convert_to_tsobject | ||
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT | ||
from pandas._libs.tslibs.timedeltas cimport convert_to_timedelta64 | ||
from pandas._libs.tslibs.timezones cimport get_timezone, tz_compare | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. putting tslibs imports before non-tslibs imports (within cython files) is intentional, can we update config to preserve this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an option to have groups in (in setup.cfg)
we can achieve the desired behavior but it will be applied across all files (py, pyx, pxi). Edit:I have opened an issue at ref: PyCQA/isort#1162 |
||
|
||
# constants that will be compared to potentially arbitrarily large | ||
# python int | ||
|
@@ -1320,8 +1320,7 @@ def infer_dtype(value: object, skipna: bool = True) -> str: | |
else: | ||
if not isinstance(value, list): | ||
value = list(value) | ||
from pandas.core.dtypes.cast import ( | ||
construct_1d_object_array_from_listlike) | ||
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike | ||
values = construct_1d_object_array_from_listlike(value) | ||
|
||
# make contiguous | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
alignment and a host of useful data manipulation methods having to do with the | ||
labeling information | ||
""" | ||
|
||
import collections | ||
from collections import abc | ||
import datetime | ||
|
@@ -35,7 +34,7 @@ | |
import warnings | ||
|
||
import numpy as np | ||
import numpy.ma as ma | ||
from numpy import ma | ||
|
||
from pandas._config import get_option | ||
|
||
|
@@ -133,6 +132,7 @@ | |
|
||
if TYPE_CHECKING: | ||
from pandas.core.groupby.generic import DataFrameGroupBy | ||
|
||
from pandas.io.formats.style import Styler | ||
|
||
# --------------------------------------------------------------------- | ||
|
@@ -438,7 +438,7 @@ def __init__( | |
elif isinstance(data, dict): | ||
mgr = init_dict(data, index, columns, dtype=dtype) | ||
elif isinstance(data, ma.MaskedArray): | ||
import numpy.ma.mrecords as mrecords | ||
from numpy.ma import mrecords | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm actually now that I think about it is this an isort thing or something you are suggesting as a standard? These aren't entirely equivalent and this change is more prone to circular imports. The former is actually suggest by Guido as the way to go so I don't think this is worth changing. (can't find link atm, but its somewhere in the Python docs) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in fact an The first commit is the changes made by from foo.bar import baz as baz There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MomIsBestFriend here is what I was describing:
So while this is inside a function, I think still not worth changing to a usage that is discouraged by Guido himself There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @WillAyd for sending the link! I have opened an issue about this discussion at xref PyCQA/isort#1164 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regardless of the
|
||
|
||
# masked recarray | ||
if isinstance(data, mrecords.MaskedRecords): | ||
|
@@ -4621,8 +4621,9 @@ def duplicated( | |
------- | ||
Series | ||
""" | ||
from pandas._libs.hashtable import _SIZE_HINT_LIMIT, duplicated_int64 | ||
|
||
from pandas.core.sorting import get_group_index | ||
from pandas._libs.hashtable import duplicated_int64, _SIZE_HINT_LIMIT | ||
|
||
if self.empty: | ||
return Series(dtype=bool) | ||
|
@@ -5455,7 +5456,7 @@ def combine_first(self, other: "DataFrame") -> "DataFrame": | |
1 0.0 3.0 1.0 | ||
2 NaN 3.0 1.0 | ||
""" | ||
import pandas.core.computation.expressions as expressions | ||
from pandas.core.computation import expressions | ||
|
||
def extract_values(arr): | ||
# Does two things: | ||
|
@@ -5602,7 +5603,7 @@ def update( | |
1 2 500.0 | ||
2 3 6.0 | ||
""" | ||
import pandas.core.computation.expressions as expressions | ||
from pandas.core.computation import expressions | ||
|
||
# TODO: Support other joins | ||
if join != "left": # pragma: no cover | ||
|
@@ -7161,8 +7162,8 @@ def join( | |
def _join_compat( | ||
self, other, on=None, how="left", lsuffix="", rsuffix="", sort=False | ||
): | ||
from pandas.core.reshape.merge import merge | ||
from pandas.core.reshape.concat import concat | ||
from pandas.core.reshape.merge import merge | ||
|
||
if isinstance(other, Series): | ||
if other.name is None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is a viable way to avoid this newline (and the one on 45), id like to maintain the pattern of keeping all the numpy imports together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't achieve that unfortunately, my guess is that
isort
is separatesimport
andcimport
even if it's importing the same library/module