Skip to content

Commit 7bde715

Browse files
jbrockmendelNo-Stream
authored andcommitted
Separate out strptime.pyx from tslib (pandas-dev#17342)
1 parent c1997d4 commit 7bde715

File tree

8 files changed

+675
-610
lines changed

8 files changed

+675
-610
lines changed

pandas/_libs/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# flake8: noqa
23

34
from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime

pandas/_libs/src/datetime.pxd

+15
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ cdef extern from "datetime/np_datetime.h":
9494
PANDAS_DATETIMEUNIT fr,
9595
pandas_datetimestruct *result) nogil
9696
int days_per_month_table[2][12]
97+
pandas_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS
9798

9899
int dayofweek(int y, int m, int d) nogil
99100
int is_leapyear(int64_t year) nogil
@@ -161,3 +162,17 @@ cdef inline int64_t _date_to_datetime64(object val,
161162
dts.hour = dts.min = dts.sec = dts.us = 0
162163
dts.ps = dts.as = 0
163164
return pandas_datetimestruct_to_datetime(PANDAS_FR_ns, dts)
165+
166+
167+
cdef inline bint check_dts_bounds(pandas_datetimestruct *dts):
168+
"""Returns True if an error needs to be raised"""
169+
cdef:
170+
bint error = False
171+
172+
if (dts.year <= 1677 and
173+
cmp_pandas_datetimestruct(dts, &_NS_MIN_DTS) == -1):
174+
error = True
175+
elif (dts.year >= 2262 and
176+
cmp_pandas_datetimestruct(dts, &_NS_MAX_DTS) == 1):
177+
error = True
178+
return error

pandas/_libs/src/datetime/np_datetime.c

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
4040
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
4141
#endif
4242

43+
const pandas_datetimestruct _NS_MIN_DTS = {
44+
1677, 9, 21, 0, 12, 43, 145225, 0, 0};
45+
const pandas_datetimestruct _NS_MAX_DTS = {
46+
2262, 4, 11, 23, 47, 16, 854775, 807000, 0};
47+
48+
4349
const int days_per_month_table[2][12] = {
4450
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
4551
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

pandas/_libs/src/datetime/np_datetime.h

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ typedef struct {
5454
int num;
5555
} pandas_datetime_metadata;
5656

57+
extern const pandas_datetimestruct _NS_MIN_DTS;
58+
extern const pandas_datetimestruct _NS_MAX_DTS;
59+
5760
// stuff pandas needs
5861
// ----------------------------------------------------------------------------
5962

0 commit comments

Comments
 (0)