Skip to content

Commit fe1bfd7

Browse files
jbrockmendeljreback
authored andcommitted
import from np_datetime instead of src/datetime (#18312)
1 parent c2590b3 commit fe1bfd7

File tree

10 files changed

+37
-48
lines changed

10 files changed

+37
-48
lines changed

pandas/_libs/period.pyx

+6-8
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,29 @@ from pandas.compat import PY2
1919
cimport cython
2020

2121
from tslibs.np_datetime cimport (pandas_datetimestruct,
22-
dtstruct_to_dt64, dt64_to_dtstruct)
23-
from datetime cimport is_leapyear
22+
dtstruct_to_dt64, dt64_to_dtstruct,
23+
is_leapyear)
2424

2525

2626
cimport util
2727
from util cimport is_period_object, is_string_object, INT32_MIN
2828

2929
from lib cimport is_null_datetimelike
30-
from pandas._libs import tslib
31-
from pandas._libs.tslib import Timestamp, iNaT
30+
from pandas._libs.tslib import Timestamp
3231
from tslibs.timezones cimport (
33-
is_utc, is_tzlocal, get_utcoffset, get_dst_info, maybe_get_tz)
32+
is_utc, is_tzlocal, get_utcoffset, get_dst_info)
3433
from tslibs.timedeltas cimport delta_to_nanoseconds
3534

3635
from tslibs.parsing import (parse_time_string, NAT_SENTINEL,
3736
_get_rule_month, _MONTH_NUMBERS)
3837
from tslibs.frequencies cimport get_freq_code
3938
from tslibs.resolution import resolution, Resolution
40-
from tslibs.nattype import nat_strings, NaT
41-
from tslibs.nattype cimport _nat_scalar_rules
39+
from tslibs.nattype import nat_strings, NaT, iNaT
40+
from tslibs.nattype cimport _nat_scalar_rules, NPY_NAT
4241

4342
from pandas.tseries import offsets
4443
from pandas.tseries import frequencies
4544

46-
cdef int64_t NPY_NAT = util.get_nat()
4745

4846
cdef extern from "period_helper.h":
4947
ctypedef struct date_info:

pandas/_libs/tslib.pyx

+7-14
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ from cpython.datetime cimport (PyDelta_Check, PyTZInfo_Check,
3838
# import datetime C API
3939
PyDateTime_IMPORT
4040
# this is our datetime.pxd
41-
from datetime cimport (
42-
pandas_datetime_to_datetimestruct,
43-
days_per_month_table,
44-
PANDAS_DATETIMEUNIT,
45-
_string_to_dts,
46-
is_leapyear,
47-
dayofweek,
48-
PANDAS_FR_ns)
41+
from datetime cimport pandas_datetime_to_datetimestruct, _string_to_dts
4942

5043
# stdlib datetime imports
5144
from datetime import time as datetime_time
@@ -55,11 +48,14 @@ from tslibs.np_datetime cimport (check_dts_bounds,
5548
reverse_ops,
5649
cmp_scalar,
5750
pandas_datetimestruct,
51+
PANDAS_DATETIMEUNIT, PANDAS_FR_ns,
5852
dt64_to_dtstruct, dtstruct_to_dt64,
5953
pydatetime_to_dt64, pydate_to_dt64,
6054
npy_datetime,
6155
get_datetime64_unit, get_datetime64_value,
62-
get_timedelta64_value)
56+
get_timedelta64_value,
57+
days_per_month_table,
58+
dayofweek, is_leapyear)
6359
from tslibs.np_datetime import OutOfBoundsDatetime
6460

6561
from .tslibs.parsing import parse_datetime_string
@@ -75,9 +71,6 @@ UTC = pytz.utc
7571
import_array()
7672

7773

78-
cdef int64_t NPY_NAT = util.get_nat()
79-
iNaT = NPY_NAT
80-
8174
from tslibs.timedeltas cimport cast_from_unit, delta_to_nanoseconds
8275
from tslibs.timedeltas import Timedelta
8376
from tslibs.timezones cimport (
@@ -95,8 +88,8 @@ from tslibs.conversion cimport (tz_convert_single, _TSObject,
9588
from tslibs.conversion import (tz_localize_to_utc,
9689
tz_convert_single, date_normalize)
9790

98-
from tslibs.nattype import NaT, nat_strings
99-
from tslibs.nattype cimport _checknull_with_nat
91+
from tslibs.nattype import NaT, nat_strings, iNaT
92+
from tslibs.nattype cimport _checknull_with_nat, NPY_NAT
10093

10194

10295
cdef inline object create_timestamp_from_ts(

pandas/_libs/tslibs/conversion.pyx

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ PyDateTime_IMPORT
2020

2121
from np_datetime cimport (check_dts_bounds,
2222
pandas_datetimestruct,
23+
PANDAS_DATETIMEUNIT, PANDAS_FR_ns,
24+
npy_datetime,
2325
dt64_to_dtstruct, dtstruct_to_dt64,
26+
get_datetime64_unit, get_datetime64_value,
2427
pydatetime_to_dt64)
2528

26-
from datetime cimport (pandas_datetime_to_datetimestruct,
27-
PANDAS_DATETIMEUNIT, PANDAS_FR_ns, npy_datetime,
28-
_string_to_dts,
29-
get_datetime64_unit, get_datetime64_value)
29+
from datetime cimport pandas_datetime_to_datetimestruct, _string_to_dts
3030

31-
cimport util
3231
from util cimport (is_string_object,
3332
is_datetime64_object,
3433
is_integer_object, is_float_object)
@@ -41,10 +40,10 @@ from timezones cimport (
4140
from parsing import parse_datetime_string
4241

4342
from nattype import nat_strings, NaT
43+
from nattype cimport NPY_NAT
4444

4545
# ----------------------------------------------------------------------
4646
# Constants
47-
cdef int64_t NPY_NAT = util.get_nat()
4847

4948
cdef int64_t DAY_NS = 86400000000000LL
5049

pandas/_libs/tslibs/fields.pyx

+3-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,9 @@ np.import_array()
1818

1919

2020
from np_datetime cimport (pandas_datetimestruct, pandas_timedeltastruct,
21-
dt64_to_dtstruct, td64_to_tdstruct)
22-
23-
from datetime cimport (
24-
days_per_month_table,
25-
is_leapyear,
26-
dayofweek)
27-
28-
cimport util
29-
30-
cdef int64_t NPY_NAT = util.get_nat()
21+
dt64_to_dtstruct, td64_to_tdstruct,
22+
days_per_month_table, is_leapyear, dayofweek)
23+
from nattype cimport NPY_NAT
3124

3225

3326
def build_field_sarray(ndarray[int64_t] dtindex):

pandas/_libs/tslibs/nattype.pxd

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# -*- coding: utf-8 -*-
22
# cython: profile=False
33

4+
from numpy cimport int64_t
5+
cdef int64_t NPY_NAT
6+
47
cdef bint _nat_scalar_rules[6]
58

69
cdef bint _checknull_with_nat(object val)

pandas/_libs/tslibs/nattype.pyx

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ from util cimport (get_nat,
2626
nat_strings = set(['NaT', 'nat', 'NAT', 'nan', 'NaN', 'NAN'])
2727

2828
cdef int64_t NPY_NAT = get_nat()
29+
iNaT = NPY_NAT # python-visible constant
2930

3031
cdef bint _nat_scalar_rules[6]
3132
_nat_scalar_rules[Py_EQ] = False

pandas/_libs/tslibs/np_datetime.pxd

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ cdef extern from "../src/datetime/np_datetime.h":
5050
PANDAS_FR_fs
5151
PANDAS_FR_as
5252

53+
int days_per_month_table[2][12]
54+
int dayofweek(int y, int m, int d) nogil
55+
int is_leapyear(int64_t year) nogil
56+
57+
5358
cdef int reverse_ops[6]
5459

5560
cdef bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1

pandas/_libs/tslibs/strptime.pyx

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ from cpython.datetime cimport datetime
3636
from np_datetime cimport (check_dts_bounds,
3737
dtstruct_to_dt64, pandas_datetimestruct)
3838

39-
from util cimport is_string_object, get_nat
39+
from util cimport is_string_object
4040

41-
cdef int64_t NPY_NAT = get_nat()
42-
43-
from nattype cimport _checknull_with_nat
41+
from nattype cimport _checknull_with_nat, NPY_NAT
4442
from nattype import nat_strings
4543

4644

pandas/_libs/tslibs/timedeltas.pyx

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ from np_datetime cimport (cmp_scalar, reverse_ops, td64_to_tdstruct,
3030
pandas_timedeltastruct)
3131

3232
from nattype import nat_strings, NaT
33-
from nattype cimport _checknull_with_nat
33+
from nattype cimport _checknull_with_nat, NPY_NAT
3434

3535
# ----------------------------------------------------------------------
3636
# Constants
3737

38-
cdef int64_t NPY_NAT = util.get_nat()
39-
4038
cdef int64_t DAY_NS = 86400000000000LL
4139

4240
# components named tuple
@@ -872,7 +870,7 @@ class Timedelta(_Timedelta):
872870

873871
if isinstance(value, Timedelta):
874872
value = value.value
875-
elif util.is_string_object(value):
873+
elif is_string_object(value):
876874
value = np.timedelta64(parse_timedelta_string(value))
877875
elif PyDelta_Check(value):
878876
value = convert_to_timedelta64(value, 'ns')
@@ -882,7 +880,7 @@ class Timedelta(_Timedelta):
882880
value = value.astype('timedelta64[ns]')
883881
elif hasattr(value, 'delta'):
884882
value = np.timedelta64(delta_to_nanoseconds(value.delta), 'ns')
885-
elif is_integer_object(value) or util.is_float_object(value):
883+
elif is_integer_object(value) or is_float_object(value):
886884
# unit=None is de-facto 'ns'
887885
value = convert_to_timedelta64(value, unit)
888886
elif _checknull_with_nat(value):

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,14 @@ def pxd(name):
553553
'_libs.tslibs.conversion': {
554554
'pyxfile': '_libs/tslibs/conversion',
555555
'pxdfiles': ['_libs/src/util',
556+
'_libs/tslibs/nattype',
556557
'_libs/tslibs/timezones',
557558
'_libs/tslibs/timedeltas'],
558559
'depends': tseries_depends,
559560
'sources': np_datetime_sources},
560561
'_libs.tslibs.fields': {
561562
'pyxfile': '_libs/tslibs/fields',
562-
'pxdfiles': ['_libs/src/util'],
563+
'pxdfiles': ['_libs/tslibs/nattype'],
563564
'depends': tseries_depends,
564565
'sources': np_datetime_sources},
565566
'_libs.tslibs.frequencies': {

0 commit comments

Comments
 (0)