Skip to content

Commit

Permalink
remove unused time conversion funcs (pandas-dev#17711)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and No-Stream committed Nov 28, 2017
1 parent 5a998a8 commit f80ae51
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 95 deletions.
31 changes: 2 additions & 29 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,19 @@ cimport util

import numpy as np

cimport tslib
from tslib cimport _to_i8

from hashtable cimport HashTable

from tslibs.timezones cimport is_utc, get_utcoffset
from pandas._libs import tslib, algos, hashtable as _hash
from pandas._libs import algos, hashtable as _hash
from pandas._libs.tslib import Timestamp, Timedelta
from datetime import datetime, timedelta

from datetime cimport (get_datetime64_value, _pydatetime_to_dts,
pandas_datetimestruct)

from cpython cimport PyTuple_Check, PyList_Check

cdef extern from "datetime.h":
bint PyDateTime_Check(object o)
void PyDateTime_IMPORT()

cdef int64_t iNaT = util.get_nat()


PyDateTime_IMPORT

cdef extern from "Python.h":
int PySlice_Check(object)

Expand Down Expand Up @@ -540,23 +530,6 @@ cpdef convert_scalar(ndarray arr, object value):

return value

cdef inline _to_i8(object val):
cdef pandas_datetimestruct dts
try:
return val.value
except AttributeError:
if util.is_datetime64_object(val):
return get_datetime64_value(val)
elif PyDateTime_Check(val):
tzinfo = getattr(val, 'tzinfo', None)
# Save the original date value so we can get the utcoffset from it.
ival = _pydatetime_to_dts(val, &dts)
if tzinfo is not None and not is_utc(tzinfo):
offset = get_utcoffset(tzinfo, val)
ival -= tslib._delta_to_nanoseconds(offset)
return ival
return val


cdef class MultiIndexObjectEngine(ObjectEngine):
"""
Expand Down
63 changes: 0 additions & 63 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,11 @@ cdef double NaN = <double> np.NaN
cdef double nan = NaN
cdef double NAN = nan

from datetime import datetime as pydatetime

# this is our tseries.pxd
from datetime cimport (
get_timedelta64_value, get_datetime64_value,
npy_timedelta, npy_datetime,
PyDateTime_Check, PyDate_Check, PyTime_Check, PyDelta_Check,
PyDateTime_GET_YEAR,
PyDateTime_GET_MONTH,
PyDateTime_GET_DAY,
PyDateTime_DATE_GET_HOUR,
PyDateTime_DATE_GET_MINUTE,
PyDateTime_DATE_GET_SECOND,
PyDateTime_IMPORT)


Expand Down Expand Up @@ -132,61 +124,6 @@ def memory_usage_of_objects(ndarray[object, ndim=1] arr):
s += arr[i].__sizeof__()
return s

#----------------------------------------------------------------------
# datetime / io related

cdef int _EPOCH_ORD = 719163

from datetime import date as pydate

cdef inline int64_t gmtime(object date):
cdef int y, m, d, h, mn, s, days

y = PyDateTime_GET_YEAR(date)
m = PyDateTime_GET_MONTH(date)
d = PyDateTime_GET_DAY(date)
h = PyDateTime_DATE_GET_HOUR(date)
mn = PyDateTime_DATE_GET_MINUTE(date)
s = PyDateTime_DATE_GET_SECOND(date)

days = pydate(y, m, 1).toordinal() - _EPOCH_ORD + d - 1
return ((<int64_t> (((days * 24 + h) * 60 + mn))) * 60 + s) * 1000


cpdef object to_datetime(int64_t timestamp):
return pydatetime.utcfromtimestamp(timestamp / 1000.0)


cpdef object to_timestamp(object dt):
return gmtime(dt)


def array_to_timestamp(ndarray[object, ndim=1] arr):
cdef int i, n
cdef ndarray[int64_t, ndim=1] result

n = len(arr)
result = np.empty(n, dtype=np.int64)

for i from 0 <= i < n:
result[i] = gmtime(arr[i])

return result


def time64_to_datetime(ndarray[int64_t, ndim=1] arr):
cdef int i, n
cdef ndarray[object, ndim=1] result

n = len(arr)
result = np.empty(n, dtype=object)

for i from 0 <= i < n:
result[i] = to_datetime(arr[i])

return result


#----------------------------------------------------------------------
# isnull / notnull related

Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/tslib.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ cdef convert_to_tsobject(object, object, object, bint, bint)
cpdef convert_to_timedelta64(object, object)
cdef bint _nat_scalar_rules[6]
cdef bint _check_all_nulls(obj)

cdef _to_i8(object val)
13 changes: 12 additions & 1 deletion pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3416,7 +3416,18 @@ def cast_to_nanoseconds(ndarray arr):
return result


def pydt_to_i8(object pydt):
cdef inline _to_i8(object val):
cdef pandas_datetimestruct dts
try:
return val.value
except AttributeError:
if is_datetime64_object(val):
return get_datetime64_value(val)
elif PyDateTime_Check(val):
return Timestamp(val).value
return val

cpdef pydt_to_i8(object pydt):
"""
Convert to int64 representation compatible with numpy datetime64; converts
to UTC
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import numpy as np
from pandas import (Series, DataFrame, Panel, Panel4D, Index,
MultiIndex, Int64Index, isna, concat,
MultiIndex, Int64Index, isna, concat, to_datetime,
SparseSeries, SparseDataFrame, PeriodIndex,
DatetimeIndex, TimedeltaIndex)
from pandas.core import config
Expand Down Expand Up @@ -4529,7 +4529,7 @@ def _unconvert_index(data, kind, encoding=None):
def _unconvert_index_legacy(data, kind, legacy=False, encoding=None):
kind = _ensure_decoded(kind)
if kind == u('datetime'):
index = lib.time64_to_datetime(data)
index = to_datetime(data)
elif kind in (u('integer')):
index = np.asarray(data, dtype=object)
elif kind in (u('string')):
Expand Down

0 comments on commit f80ae51

Please sign in to comment.