Skip to content

cleanup unused imports, constants #18119

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 5 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 9 additions & 15 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ cdef bint PY3 = (sys.version_info[0] >= 3)

from numpy cimport *

# initialize numpy
np.import_array()
np.import_ufunc()

from libc.stdlib cimport malloc, free

Expand Down Expand Up @@ -53,23 +55,15 @@ from datetime cimport get_timedelta64_value, get_datetime64_value


from tslib cimport _check_all_nulls
import tslib
from tslib import NaT, Timestamp, Timedelta
import interval
from tslib import NaT, Timestamp, Timedelta, array_to_datetime
Copy link
Contributor

Choose a reason for hiding this comment

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

i dont' really like this but i guess its how it is currently. this is a python level dep between lib and tslib.

Copy link
Member Author

Choose a reason for hiding this comment

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

Timestamp and Timedelta aren't used in lib. A couple of modules use lib.Timestamp instead of tslib.Timestamp. The NaT dependency could be imported directly from tslibs.nattype. array_to_datetime... not really any good options.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, just mentioning it

from interval import Interval

cdef int64_t NPY_NAT = util.get_nat()

cimport util
from util cimport is_array, _checknull, _checknan

cdef extern from "math.h":
double sqrt(double x)
double fabs(double)

# initialize numpy
import_array()
import_ufunc()
from libc.math cimport sqrt, fabs


def values_from_object(object o):
Expand Down Expand Up @@ -152,7 +146,7 @@ cpdef bint checknull_old(object val):
elif is_array(val):
return False
else:
return util._checknull(val)
return _checknull(val)


cpdef bint isposinf_scalar(object val):
Expand Down Expand Up @@ -788,13 +782,13 @@ def scalar_binop(ndarray[object] values, object val, object op):
object x

result = np.empty(n, dtype=object)
if util._checknull(val):
if _checknull(val):
result.fill(val)
return result

for i in range(n):
x = values[i]
if util._checknull(x):
if _checknull(x):
result[i] = x
else:
result[i] = op(x, val)
Expand All @@ -821,9 +815,9 @@ def vec_binop(ndarray[object] left, ndarray[object] right, object op):
try:
result[i] = op(x, y)
except TypeError:
if util._checknull(x):
if _checknull(x):
result[i] = x
elif util._checknull(y):
elif _checknull(y):
result[i] = y
else:
raise
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/properties.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-

from cython cimport Py_ssize_t

Expand Down
69 changes: 6 additions & 63 deletions pandas/_libs/src/datetime.pxd
Original file line number Diff line number Diff line change
@@ -1,60 +1,25 @@
# cython: profile=False
from numpy cimport int64_t, int32_t, npy_int64, npy_int32, ndarray
from cpython cimport PyObject
from numpy cimport int64_t, npy_int64, npy_int32

from cpython cimport PyUnicode_Check, PyUnicode_AsASCIIString


cdef extern from "datetime.h":

ctypedef class datetime.date [object PyDateTime_Date]:
pass

ctypedef class datetime.datetime [object PyDateTime_DateTime]:
pass

ctypedef class datetime.timedelta [object PyDateTime_Delta]:
pass

void PyDateTime_IMPORT()

int PyDateTime_GET_YEAR(date)
int PyDateTime_GET_MONTH(date)
int PyDateTime_GET_DAY(date)
int PyDateTime_DATE_GET_HOUR(object o)
int PyDateTime_DATE_GET_MINUTE(object o)
int PyDateTime_DATE_GET_SECOND(object o)
int PyDateTime_DATE_GET_MICROSECOND(object o)
int PyDateTime_TIME_GET_HOUR(object o)
int PyDateTime_TIME_GET_MINUTE(object o)
int PyDateTime_TIME_GET_SECOND(object o)
int PyDateTime_TIME_GET_MICROSECOND(object o)
bint PyDateTime_Check(object o)
bint PyDate_Check(object o)
bint PyTime_Check(object o)
bint PyDelta_Check(object o)
object PyDateTime_FromDateAndTime(int year, int month, int day, int hour,
int minute, int second, int us)

cdef extern from "numpy/ndarrayobject.h":

ctypedef int64_t npy_timedelta
ctypedef int64_t npy_datetime

ctypedef enum NPY_CASTING:
NPY_NO_CASTING
NPY_EQUIV_CASTING
NPY_SAFE_CASTING
NPY_SAME_KIND_CASTING
NPY_UNSAFE_CASTING

NPY_NO_CASTING
NPY_EQUIV_CASTING
NPY_SAFE_CASTING
NPY_SAME_KIND_CASTING
NPY_UNSAFE_CASTING

cdef extern from "numpy_helper.h":
npy_datetime get_datetime64_value(object o)
npy_timedelta get_timedelta64_value(object o)

cdef extern from "numpy/npy_common.h":

ctypedef unsigned char npy_bool

cdef extern from "datetime/np_datetime.h":
Expand All @@ -79,16 +44,12 @@ cdef extern from "datetime/np_datetime.h":
npy_int64 year
npy_int32 month, day, hour, min, sec, us, ps, as

int cmp_pandas_datetimestruct(pandas_datetimestruct *a,
pandas_datetimestruct *b)

npy_datetime pandas_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT fr,
pandas_datetimestruct *d) nogil
void pandas_datetime_to_datetimestruct(npy_datetime val,
PANDAS_DATETIMEUNIT fr,
pandas_datetimestruct *result) nogil
int days_per_month_table[2][12]
pandas_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS

int dayofweek(int y, int m, int d) nogil
int is_leapyear(int64_t year) nogil
Expand All @@ -102,10 +63,6 @@ cdef extern from "datetime/np_datetime_strings.h":
PANDAS_DATETIMEUNIT *out_bestunit,
npy_bool *out_special)

# int parse_python_string(object obj, pandas_datetimestruct *out) except -1




cdef inline int _string_to_dts(object val, pandas_datetimestruct* dts,
int* out_local, int* out_tzoffset) except? -1:
Expand Down Expand Up @@ -134,17 +91,3 @@ cdef inline int _cstring_to_dts(char *val, int length,
NPY_UNSAFE_CASTING,
dts, out_local, out_tzoffset, &out_bestunit, &special)
return result


cdef inline bint check_dts_bounds(pandas_datetimestruct *dts):
"""Returns True if an error needs to be raised"""
cdef:
bint error = False

if (dts.year <= 1677 and
cmp_pandas_datetimestruct(dts, &_NS_MIN_DTS) == -1):
error = True
elif (dts.year >= 2262 and
cmp_pandas_datetimestruct(dts, &_NS_MAX_DTS) == 1):
error = True
return error
2 changes: 1 addition & 1 deletion pandas/_libs/src/inference.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ cpdef object infer_datetimelike_array(object arr):
# convert *every* string array
if len(objs):
try:
tslib.array_to_datetime(objs, errors='raise')
array_to_datetime(objs, errors='raise')
return 'datetime'
except:
pass
Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/src/reduce.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ from distutils.version import LooseVersion

is_numpy_prior_1_6_2 = LooseVersion(np.__version__) < '1.6.2'

cdef _get_result_array(object obj,
Py_ssize_t size,
Py_ssize_t cnt):

cdef _get_result_array(object obj, Py_ssize_t size, Py_ssize_t cnt):

if isinstance(obj, np.ndarray) \
or isinstance(obj, list) and len(obj) == cnt \
Expand Down