Skip to content

CLN: update cimports #34176

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 4 commits into from
May 15, 2020
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
4 changes: 1 addition & 3 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ 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.math cimport NAN
cnp.import_array()

cdef extern from "numpy/npy_math.h":
float64_t NAN "NPY_NAN"

from pandas._libs.util cimport numeric, get_nat

from pandas._libs.algos cimport (swap, TiebreakEnumType, TIEBREAK_AVERAGE,
Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ from libc.stdlib cimport malloc, free
import numpy as np
cimport numpy as cnp
from numpy cimport ndarray, uint8_t, uint32_t, float64_t
from numpy.math cimport NAN
cnp.import_array()

cdef extern from "numpy/npy_math.h":
float64_t NAN "NPY_NAN"

from pandas._libs.khash cimport (
khiter_t,
Expand Down Expand Up @@ -54,7 +53,7 @@ from pandas._libs.khash cimport (
)


cimport pandas._libs.util as util
from pandas._libs cimport util

from pandas._libs.missing cimport checknull

Expand Down
9 changes: 4 additions & 5 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ from numpy cimport (
cnp.import_array()


cimport pandas._libs.util as util
from pandas._libs cimport util

from pandas._libs.tslibs import Period, Timedelta
from pandas._libs.tslibs.nattype cimport c_NaT as NaT
from pandas._libs.tslibs.base cimport ABCTimestamp
from pandas._libs.tslibs.base cimport ABCTimestamp, ABCTimedelta, ABCPeriod

from pandas._libs.hashtable cimport HashTable

Expand Down Expand Up @@ -470,7 +469,7 @@ cdef class TimedeltaEngine(DatetimeEngine):
return 'm8[ns]'

cdef int64_t _unbox_scalar(self, scalar) except? -1:
if not (isinstance(scalar, Timedelta) or scalar is NaT):
if not (isinstance(scalar, ABCTimedelta) or scalar is NaT):
raise TypeError(scalar)
return scalar.value

Expand All @@ -480,7 +479,7 @@ cdef class PeriodEngine(Int64Engine):
cdef int64_t _unbox_scalar(self, scalar) except? -1:
if scalar is NaT:
return scalar.value
if isinstance(scalar, Period):
if isinstance(scalar, ABCPeriod):
# NB: we assume that we have the correct freq here.
return scalar.ordinal
raise TypeError(scalar)
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cython
from collections import defaultdict

import cython
from cython import Py_ssize_t

from cpython.slice cimport PySlice_GetIndicesEx
Expand Down
11 changes: 5 additions & 6 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ from numpy cimport (
cnp.import_array()


cimport pandas._libs.util as util
from pandas._libs cimport util

from pandas._libs.hashtable cimport Int64Vector
from pandas._libs.tslibs.util cimport (
Expand All @@ -42,8 +42,7 @@ from pandas._libs.tslibs.util cimport (
is_timedelta64_object,
)

from pandas._libs.tslibs import Timestamp
from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._libs.tslibs.base cimport ABCTimestamp, ABCTimedelta
from pandas._libs.tslibs.timezones cimport tz_compare


Expand Down Expand Up @@ -329,7 +328,7 @@ cdef class Interval(IntervalMixin):
raise ValueError(f"invalid option for 'closed': {closed}")
if not left <= right:
raise ValueError("left side of interval must be <= right side")
if (isinstance(left, Timestamp) and
if (isinstance(left, ABCTimestamp) and
not tz_compare(left.tzinfo, right.tzinfo)):
# GH 18538
raise ValueError("left and right must have the same time zone, got "
Expand All @@ -341,7 +340,7 @@ cdef class Interval(IntervalMixin):
def _validate_endpoint(self, endpoint):
# GH 23013
if not (is_integer_object(endpoint) or is_float_object(endpoint) or
isinstance(endpoint, (Timestamp, Timedelta))):
isinstance(endpoint, (ABCTimestamp, ABCTimedelta))):
raise ValueError("Only numeric, Timestamp and Timedelta endpoints "
"are allowed when constructing an Interval.")

Expand Down Expand Up @@ -371,7 +370,7 @@ cdef class Interval(IntervalMixin):
right = self.right

# TODO: need more general formatting methodology here
if isinstance(left, Timestamp) and isinstance(right, Timestamp):
if isinstance(left, ABCTimestamp) and isinstance(right, ABCTimestamp):
left = left._short_repr
right = right._short_repr

Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import abc
from decimal import Decimal

import warnings

import cython
Expand Down Expand Up @@ -63,7 +62,7 @@ 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 cimport util
from pandas._libs.util cimport is_nan, UINT64_MAX, INT64_MAX, INT64_MIN

from pandas._libs.tslib import array_to_datetime
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cimport numpy as cnp
from numpy cimport ndarray, int64_t, uint8_t, float64_t
cnp.import_array()

cimport pandas._libs.util as util
from pandas._libs cimport util


from pandas._libs.tslibs.np_datetime cimport get_datetime64_value, get_timedelta64_value
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cimport numpy as cnp
from numpy cimport ndarray, uint8_t, uint64_t, int64_t, float64_t
cnp.import_array()

cimport pandas._libs.util as util
from pandas._libs cimport util
from pandas._libs.util cimport UINT64_MAX, INT64_MAX, INT64_MIN
import pandas._libs.lib as lib

Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from numpy cimport (ndarray,
flatiter)
cnp.import_array()

cimport pandas._libs.util as util
from pandas._libs cimport util
from pandas._libs.lib import maybe_convert_objects, is_scalar


Expand Down Expand Up @@ -603,7 +603,7 @@ cdef class BlockSlider:
arr.shape[1] = 0


def compute_reduction(arr: np.ndarray, f, axis: int = 0, dummy=None, labels=None):
def compute_reduction(arr: ndarray, f, axis: int = 0, dummy=None, labels=None):
Copy link
Member

Choose a reason for hiding this comment

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

mypy is not checking .pyx files. I suspect we would want to keep the np.ndarray annotation here since ndarray is a cimport.

"""

Parameters
Expand Down
5 changes: 3 additions & 2 deletions pandas/_libs/reshape.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ from numpy cimport (
uint64_t,
)

cimport numpy as cnp
import numpy as np
from pandas._libs.lib cimport c_is_list_like
cimport numpy as cnp
cnp.import_array()

from pandas._libs.lib cimport c_is_list_like

ctypedef fused reshape_t:
uint8_t
uint16_t
Expand Down
8 changes: 6 additions & 2 deletions pandas/_libs/testing.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import numpy as np
from numpy cimport import_array
import_array()

from pandas._libs.util cimport is_array

from pandas.core.dtypes.missing import isna, array_equivalent
from pandas.core.dtypes.common import is_dtype_equal
Expand Down Expand Up @@ -116,8 +120,8 @@ cpdef assert_almost_equal(a, b,
assert a == b, f"{a} != {b}"
return True

a_is_ndarray = isinstance(a, np.ndarray)
b_is_ndarray = isinstance(b, np.ndarray)
a_is_ndarray = is_array(a)
b_is_ndarray = is_array(b)

if obj is None:
if a_is_ndarray or b_is_ndarray:
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cnp.import_array()


from pandas._libs.tslibs cimport util
from pandas._libs.tslibs.util cimport is_integer_object
from pandas._libs.tslibs.util cimport is_integer_object, is_datetime64_object

from pandas._libs.tslibs.base cimport ABCTick, ABCTimestamp, is_tick_object

Expand Down Expand Up @@ -161,7 +161,7 @@ def apply_wraps(func):
elif isinstance(other, (timedelta, BaseOffset)):
# timedelta path
return func(self, other)
elif isinstance(other, (np.datetime64, datetime, date)):
elif isinstance(other, (datetime, date)) or is_datetime64_object(other):
other = Timestamp(other)
else:
# This will end up returning NotImplemented back in __add__
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/strptime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import locale
import calendar
import re

from cpython cimport datetime

from _thread import allocate_lock as _thread_allocate_lock

import pytz

import numpy as np
from numpy cimport int64_t

cimport cpython.datetime as datetime

from pandas._libs.tslibs.np_datetime cimport (
check_dts_bounds, dtstruct_to_dt64, npy_datetimestruct)

Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ from pandas._libs.tslibs.util cimport (
is_timedelta64_object, is_array,
)

from pandas._libs.tslibs.base cimport ABCTimestamp, is_tick_object
from pandas._libs.tslibs.base cimport ABCTimedelta, ABCTimestamp, is_tick_object

from pandas._libs.tslibs cimport ccalendar

Expand Down Expand Up @@ -355,10 +355,10 @@ cdef class _Timestamp(ABCTimestamp):

elif PyDelta_Check(other):
# logic copied from delta_to_nanoseconds to prevent circular import
if hasattr(other, 'delta'):
if isinstance(other, ABCTimedelta):
# pd.Timedelta
nanos = other.value
elif PyDelta_Check(other):
else:
nanos = (other.days * 24 * 60 * 60 * 1000000 +
other.seconds * 1000000 +
other.microseconds) * 1000
Expand Down