Skip to content

REF: make nat_strings cimport-able #34105

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 2 commits into from
May 11, 2020
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
7 changes: 5 additions & 2 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ from pandas._libs.tslibs.conversion cimport (
_TSObject, convert_datetime_to_tsobject,
get_datetime64_nanos)

from pandas._libs.tslibs.nattype import nat_strings
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT
from pandas._libs.tslibs.nattype cimport (
NPY_NAT,
c_NaT as NaT,
c_nat_strings as nat_strings,
)

from pandas._libs.tslibs.offsets cimport to_offset

Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"NaT",
"NaTType",
"iNaT",
"nat_strings",
"is_null_datetimelike",
"OutOfBoundsDatetime",
"IncompatibleFrequency",
Expand All @@ -17,7 +18,7 @@


from .conversion import localize_pydatetime
from .nattype import NaT, NaTType, iNaT, is_null_datetimelike
from .nattype import NaT, NaTType, iNaT, is_null_datetimelike, nat_strings
from .np_datetime import OutOfBoundsDatetime
from .period import IncompatibleFrequency, Period
from .timedeltas import Timedelta, delta_to_nanoseconds, ints_to_pytimedelta
Expand Down
7 changes: 5 additions & 2 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ from pandas._libs.tslibs.timezones cimport (
)
from pandas._libs.tslibs.parsing import parse_datetime_string

from pandas._libs.tslibs.nattype import nat_strings
from pandas._libs.tslibs.nattype cimport (
NPY_NAT, checknull_with_nat, c_NaT as NaT)
NPY_NAT,
checknull_with_nat,
c_NaT as NaT,
c_nat_strings as nat_strings,
)

from pandas._libs.tslibs.tzconversion import tz_localize_to_utc
from pandas._libs.tslibs.tzconversion cimport (
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/nattype.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from numpy cimport int64_t
cdef int64_t NPY_NAT

cdef bint _nat_scalar_rules[6]

cdef set c_nat_strings

cdef class _NaT(datetime):
cdef readonly:
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ from pandas._libs.tslibs.base cimport is_period_object
# ----------------------------------------------------------------------
# Constants
nat_strings = {"NaT", "nat", "NAT", "nan", "NaN", "NAN"}
cdef set c_nat_strings = nat_strings

cdef int64_t NPY_NAT = util.get_nat()
iNaT = NPY_NAT # python-visible constant
Expand Down
5 changes: 4 additions & 1 deletion pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ from dateutil.parser import parse as du_parse
from pandas._config import get_option

from pandas._libs.tslibs.ccalendar cimport c_MONTH_NUMBERS
from pandas._libs.tslibs.nattype import nat_strings, NaT
from pandas._libs.tslibs.nattype cimport (
c_nat_strings as nat_strings,
c_NaT as NaT,
)
from pandas._libs.tslibs.util cimport (
is_array,
is_offset_object,
Expand Down
8 changes: 6 additions & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ from pandas._libs.tslibs.frequencies cimport (
)
from pandas._libs.tslibs.parsing import parse_time_string
from pandas._libs.tslibs.resolution import Resolution
from pandas._libs.tslibs.nattype import nat_strings
from pandas._libs.tslibs.nattype cimport (
_nat_scalar_rules, NPY_NAT, is_null_datetimelike, c_NaT as NaT)
_nat_scalar_rules,
NPY_NAT,
is_null_datetimelike,
c_NaT as NaT,
c_nat_strings as nat_strings,
)
from pandas._libs.tslibs.offsets cimport to_offset, is_tick_object
from pandas._libs.tslibs.tzconversion cimport tz_convert_utc_to_tzlocal

Expand Down
7 changes: 5 additions & 2 deletions pandas/_libs/tslibs/strptime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ cimport cpython.datetime as datetime
from pandas._libs.tslibs.np_datetime cimport (
check_dts_bounds, dtstruct_to_dt64, npy_datetimestruct)

from pandas._libs.tslibs.nattype cimport checknull_with_nat, NPY_NAT
from pandas._libs.tslibs.nattype import nat_strings
from pandas._libs.tslibs.nattype cimport (
checknull_with_nat,
NPY_NAT,
c_nat_strings as nat_strings,
)

cdef dict _parse_code_table = {'y': 0,
'Y': 1,
Expand Down
7 changes: 5 additions & 2 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ from pandas._libs.tslibs.ccalendar cimport DAY_NANOS
from pandas._libs.tslibs.np_datetime cimport (
cmp_scalar, reverse_ops, td64_to_tdstruct, pandas_timedeltastruct)

from pandas._libs.tslibs.nattype import nat_strings
from pandas._libs.tslibs.nattype cimport (
checknull_with_nat, NPY_NAT, c_NaT as NaT)
checknull_with_nat,
NPY_NAT,
c_NaT as NaT,
c_nat_strings as nat_strings,
)

# ----------------------------------------------------------------------
# Constants
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ def calc_with_mask(carg, mask):

# string with NaN-like
try:
mask = ~algorithms.isin(arg, list(tslib.nat_strings))
mask = ~algorithms.isin(arg, list(tslibs.nat_strings))
return calc_with_mask(arg, mask)
except (ValueError, OverflowError, TypeError):
pass
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/tslibs/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_namespace():
"NaTType",
"iNaT",
"is_null_datetimelike",
"nat_strings",
"NullFrequencyError",
"OutOfBoundsDatetime",
"Period",
Expand Down