Skip to content

Commit dead59a

Browse files
jbrockmendeljreback
authored andcommitted
remove unused time conversion funcs (#17711)
1 parent 458c1dc commit dead59a

File tree

5 files changed

+18
-95
lines changed

5 files changed

+18
-95
lines changed

pandas/_libs/index.pyx

+2-29
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,19 @@ cimport util
1313

1414
import numpy as np
1515

16-
cimport tslib
16+
from tslib cimport _to_i8
1717

1818
from hashtable cimport HashTable
1919

20-
from tslibs.timezones cimport is_utc, get_utcoffset
21-
from pandas._libs import tslib, algos, hashtable as _hash
20+
from pandas._libs import algos, hashtable as _hash
2221
from pandas._libs.tslib import Timestamp, Timedelta
2322
from datetime import datetime, timedelta
2423

25-
from datetime cimport (get_datetime64_value, _pydatetime_to_dts,
26-
pandas_datetimestruct)
27-
2824
from cpython cimport PyTuple_Check, PyList_Check
2925

30-
cdef extern from "datetime.h":
31-
bint PyDateTime_Check(object o)
32-
void PyDateTime_IMPORT()
33-
3426
cdef int64_t iNaT = util.get_nat()
3527

3628

37-
PyDateTime_IMPORT
38-
3929
cdef extern from "Python.h":
4030
int PySlice_Check(object)
4131

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

541531
return value
542532

543-
cdef inline _to_i8(object val):
544-
cdef pandas_datetimestruct dts
545-
try:
546-
return val.value
547-
except AttributeError:
548-
if util.is_datetime64_object(val):
549-
return get_datetime64_value(val)
550-
elif PyDateTime_Check(val):
551-
tzinfo = getattr(val, 'tzinfo', None)
552-
# Save the original date value so we can get the utcoffset from it.
553-
ival = _pydatetime_to_dts(val, &dts)
554-
if tzinfo is not None and not is_utc(tzinfo):
555-
offset = get_utcoffset(tzinfo, val)
556-
ival -= tslib._delta_to_nanoseconds(offset)
557-
return ival
558-
return val
559-
560533

561534
cdef class MultiIndexObjectEngine(ObjectEngine):
562535
"""

pandas/_libs/lib.pyx

-63
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,11 @@ cdef double NaN = <double> np.NaN
4545
cdef double nan = NaN
4646
cdef double NAN = nan
4747

48-
from datetime import datetime as pydatetime
49-
5048
# this is our tseries.pxd
5149
from datetime cimport (
5250
get_timedelta64_value, get_datetime64_value,
5351
npy_timedelta, npy_datetime,
5452
PyDateTime_Check, PyDate_Check, PyTime_Check, PyDelta_Check,
55-
PyDateTime_GET_YEAR,
56-
PyDateTime_GET_MONTH,
57-
PyDateTime_GET_DAY,
58-
PyDateTime_DATE_GET_HOUR,
59-
PyDateTime_DATE_GET_MINUTE,
60-
PyDateTime_DATE_GET_SECOND,
6153
PyDateTime_IMPORT)
6254

6355

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

135-
#----------------------------------------------------------------------
136-
# datetime / io related
137-
138-
cdef int _EPOCH_ORD = 719163
139-
140-
from datetime import date as pydate
141-
142-
cdef inline int64_t gmtime(object date):
143-
cdef int y, m, d, h, mn, s, days
144-
145-
y = PyDateTime_GET_YEAR(date)
146-
m = PyDateTime_GET_MONTH(date)
147-
d = PyDateTime_GET_DAY(date)
148-
h = PyDateTime_DATE_GET_HOUR(date)
149-
mn = PyDateTime_DATE_GET_MINUTE(date)
150-
s = PyDateTime_DATE_GET_SECOND(date)
151-
152-
days = pydate(y, m, 1).toordinal() - _EPOCH_ORD + d - 1
153-
return ((<int64_t> (((days * 24 + h) * 60 + mn))) * 60 + s) * 1000
154-
155-
156-
cpdef object to_datetime(int64_t timestamp):
157-
return pydatetime.utcfromtimestamp(timestamp / 1000.0)
158-
159-
160-
cpdef object to_timestamp(object dt):
161-
return gmtime(dt)
162-
163-
164-
def array_to_timestamp(ndarray[object, ndim=1] arr):
165-
cdef int i, n
166-
cdef ndarray[int64_t, ndim=1] result
167-
168-
n = len(arr)
169-
result = np.empty(n, dtype=np.int64)
170-
171-
for i from 0 <= i < n:
172-
result[i] = gmtime(arr[i])
173-
174-
return result
175-
176-
177-
def time64_to_datetime(ndarray[int64_t, ndim=1] arr):
178-
cdef int i, n
179-
cdef ndarray[object, ndim=1] result
180-
181-
n = len(arr)
182-
result = np.empty(n, dtype=object)
183-
184-
for i from 0 <= i < n:
185-
result[i] = to_datetime(arr[i])
186-
187-
return result
188-
189-
190127
#----------------------------------------------------------------------
191128
# isnull / notnull related
192129

pandas/_libs/tslib.pxd

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ cdef convert_to_tsobject(object, object, object, bint, bint)
44
cpdef convert_to_timedelta64(object, object)
55
cdef bint _nat_scalar_rules[6]
66
cdef bint _check_all_nulls(obj)
7+
8+
cdef _to_i8(object val)

pandas/_libs/tslib.pyx

+12-1
Original file line numberDiff line numberDiff line change
@@ -3416,7 +3416,18 @@ def cast_to_nanoseconds(ndarray arr):
34163416
return result
34173417

34183418

3419-
def pydt_to_i8(object pydt):
3419+
cdef inline _to_i8(object val):
3420+
cdef pandas_datetimestruct dts
3421+
try:
3422+
return val.value
3423+
except AttributeError:
3424+
if is_datetime64_object(val):
3425+
return get_datetime64_value(val)
3426+
elif PyDateTime_Check(val):
3427+
return Timestamp(val).value
3428+
return val
3429+
3430+
cpdef pydt_to_i8(object pydt):
34203431
"""
34213432
Convert to int64 representation compatible with numpy datetime64; converts
34223433
to UTC

pandas/io/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import numpy as np
2727
from pandas import (Series, DataFrame, Panel, Panel4D, Index,
28-
MultiIndex, Int64Index, isna, concat,
28+
MultiIndex, Int64Index, isna, concat, to_datetime,
2929
SparseSeries, SparseDataFrame, PeriodIndex,
3030
DatetimeIndex, TimedeltaIndex)
3131
from pandas.core import config
@@ -4529,7 +4529,7 @@ def _unconvert_index(data, kind, encoding=None):
45294529
def _unconvert_index_legacy(data, kind, legacy=False, encoding=None):
45304530
kind = _ensure_decoded(kind)
45314531
if kind == u('datetime'):
4532-
index = lib.time64_to_datetime(data)
4532+
index = to_datetime(data)
45334533
elif kind in (u('integer')):
45344534
index = np.asarray(data, dtype=object)
45354535
elif kind in (u('string')):

0 commit comments

Comments
 (0)