Skip to content

Separate out strptime.pyx from tslib #17342

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 16 commits into from
Sep 25, 2017
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
1 change: 1 addition & 0 deletions pandas/_libs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa

from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
Expand Down
15 changes: 15 additions & 0 deletions pandas/_libs/src/datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ cdef extern from "datetime/np_datetime.h":
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 Down Expand Up @@ -161,3 +162,17 @@ cdef inline int64_t _date_to_datetime64(object val,
dts.hour = dts.min = dts.sec = dts.us = 0
dts.ps = dts.as = 0
return pandas_datetimestruct_to_datetime(PANDAS_FR_ns, dts)


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
6 changes: 6 additions & 0 deletions pandas/_libs/src/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif

const pandas_datetimestruct _NS_MIN_DTS = {
1677, 9, 21, 0, 12, 43, 145225, 0, 0};
const pandas_datetimestruct _NS_MAX_DTS = {
2262, 4, 11, 23, 47, 16, 854775, 807000, 0};


const int days_per_month_table[2][12] = {
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
Expand Down
3 changes: 3 additions & 0 deletions pandas/_libs/src/datetime/np_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ typedef struct {
int num;
} pandas_datetime_metadata;

extern const pandas_datetimestruct _NS_MIN_DTS;
extern const pandas_datetimestruct _NS_MAX_DTS;

// stuff pandas needs
// ----------------------------------------------------------------------------

Expand Down
Loading