Skip to content

Commit 1c4114d

Browse files
authored
REF: make nat_strings cimport-able (pandas-dev#34105)
1 parent 901b1c7 commit 1c4114d

File tree

11 files changed

+36
-14
lines changed

11 files changed

+36
-14
lines changed

pandas/_libs/tslib.pyx

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ from pandas._libs.tslibs.conversion cimport (
5050
_TSObject, convert_datetime_to_tsobject,
5151
get_datetime64_nanos)
5252

53-
from pandas._libs.tslibs.nattype import nat_strings
54-
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT
53+
from pandas._libs.tslibs.nattype cimport (
54+
NPY_NAT,
55+
c_NaT as NaT,
56+
c_nat_strings as nat_strings,
57+
)
5558

5659
from pandas._libs.tslibs.offsets cimport to_offset
5760

pandas/_libs/tslibs/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"NaT",
44
"NaTType",
55
"iNaT",
6+
"nat_strings",
67
"is_null_datetimelike",
78
"OutOfBoundsDatetime",
89
"IncompatibleFrequency",
@@ -17,7 +18,7 @@
1718

1819

1920
from .conversion import localize_pydatetime
20-
from .nattype import NaT, NaTType, iNaT, is_null_datetimelike
21+
from .nattype import NaT, NaTType, iNaT, is_null_datetimelike, nat_strings
2122
from .np_datetime import OutOfBoundsDatetime
2223
from .period import IncompatibleFrequency, Period
2324
from .timedeltas import Timedelta, delta_to_nanoseconds, ints_to_pytimedelta

pandas/_libs/tslibs/conversion.pyx

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ from pandas._libs.tslibs.timezones cimport (
3333
)
3434
from pandas._libs.tslibs.parsing import parse_datetime_string
3535

36-
from pandas._libs.tslibs.nattype import nat_strings
3736
from pandas._libs.tslibs.nattype cimport (
38-
NPY_NAT, checknull_with_nat, c_NaT as NaT)
37+
NPY_NAT,
38+
checknull_with_nat,
39+
c_NaT as NaT,
40+
c_nat_strings as nat_strings,
41+
)
3942

4043
from pandas._libs.tslibs.tzconversion import tz_localize_to_utc
4144
from pandas._libs.tslibs.tzconversion cimport (

pandas/_libs/tslibs/nattype.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from numpy cimport int64_t
44
cdef int64_t NPY_NAT
55

66
cdef bint _nat_scalar_rules[6]
7-
7+
cdef set c_nat_strings
88

99
cdef class _NaT(datetime):
1010
cdef readonly:

pandas/_libs/tslibs/nattype.pyx

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ from pandas._libs.tslibs.base cimport is_period_object
3535
# ----------------------------------------------------------------------
3636
# Constants
3737
nat_strings = {"NaT", "nat", "NAT", "nan", "NaN", "NAN"}
38+
cdef set c_nat_strings = nat_strings
3839

3940
cdef int64_t NPY_NAT = util.get_nat()
4041
iNaT = NPY_NAT # python-visible constant

pandas/_libs/tslibs/parsing.pyx

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ from dateutil.parser import parse as du_parse
3333
from pandas._config import get_option
3434

3535
from pandas._libs.tslibs.ccalendar cimport c_MONTH_NUMBERS
36-
from pandas._libs.tslibs.nattype import nat_strings, NaT
36+
from pandas._libs.tslibs.nattype cimport (
37+
c_nat_strings as nat_strings,
38+
c_NaT as NaT,
39+
)
3740
from pandas._libs.tslibs.util cimport (
3841
is_array,
3942
is_offset_object,

pandas/_libs/tslibs/period.pyx

+6-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ from pandas._libs.tslibs.frequencies cimport (
6161
)
6262
from pandas._libs.tslibs.parsing import parse_time_string
6363
from pandas._libs.tslibs.resolution import Resolution
64-
from pandas._libs.tslibs.nattype import nat_strings
6564
from pandas._libs.tslibs.nattype cimport (
66-
_nat_scalar_rules, NPY_NAT, is_null_datetimelike, c_NaT as NaT)
65+
_nat_scalar_rules,
66+
NPY_NAT,
67+
is_null_datetimelike,
68+
c_NaT as NaT,
69+
c_nat_strings as nat_strings,
70+
)
6771
from pandas._libs.tslibs.offsets cimport to_offset, is_tick_object
6872
from pandas._libs.tslibs.tzconversion cimport tz_convert_utc_to_tzlocal
6973

pandas/_libs/tslibs/strptime.pyx

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ cimport cpython.datetime as datetime
1717
from pandas._libs.tslibs.np_datetime cimport (
1818
check_dts_bounds, dtstruct_to_dt64, npy_datetimestruct)
1919

20-
from pandas._libs.tslibs.nattype cimport checknull_with_nat, NPY_NAT
21-
from pandas._libs.tslibs.nattype import nat_strings
20+
from pandas._libs.tslibs.nattype cimport (
21+
checknull_with_nat,
22+
NPY_NAT,
23+
c_nat_strings as nat_strings,
24+
)
2225

2326
cdef dict _parse_code_table = {'y': 0,
2427
'Y': 1,

pandas/_libs/tslibs/timedeltas.pyx

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ from pandas._libs.tslibs.ccalendar cimport DAY_NANOS
2828
from pandas._libs.tslibs.np_datetime cimport (
2929
cmp_scalar, reverse_ops, td64_to_tdstruct, pandas_timedeltastruct)
3030

31-
from pandas._libs.tslibs.nattype import nat_strings
3231
from pandas._libs.tslibs.nattype cimport (
33-
checknull_with_nat, NPY_NAT, c_NaT as NaT)
32+
checknull_with_nat,
33+
NPY_NAT,
34+
c_NaT as NaT,
35+
c_nat_strings as nat_strings,
36+
)
3437

3538
# ----------------------------------------------------------------------
3639
# Constants

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def calc_with_mask(carg, mask):
936936

937937
# string with NaN-like
938938
try:
939-
mask = ~algorithms.isin(arg, list(tslib.nat_strings))
939+
mask = ~algorithms.isin(arg, list(tslibs.nat_strings))
940940
return calc_with_mask(arg, mask)
941941
except (ValueError, OverflowError, TypeError):
942942
pass

pandas/tests/tslibs/test_api.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_namespace():
2929
"NaTType",
3030
"iNaT",
3131
"is_null_datetimelike",
32+
"nat_strings",
3233
"NullFrequencyError",
3334
"OutOfBoundsDatetime",
3435
"Period",

0 commit comments

Comments
 (0)