Skip to content

Commit 8db5247

Browse files
committed
Merge remote-tracking branch 'upstream/master' into hist_legend
2 parents 3e4925d + 1f48d3d commit 8db5247

File tree

15 files changed

+216
-193
lines changed

15 files changed

+216
-193
lines changed

pandas/_libs/index.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ cnp.import_array()
2222
from pandas._libs cimport util
2323

2424
from pandas._libs.tslibs.nattype cimport c_NaT as NaT
25-
from pandas._libs.tslibs.base cimport ABCTimestamp, ABCTimedelta, ABCPeriod
25+
from pandas._libs.tslibs.base cimport ABCTimestamp, ABCTimedelta
26+
from pandas._libs.tslibs.period cimport is_period_object
2627

2728
from pandas._libs.hashtable cimport HashTable
2829

@@ -479,7 +480,7 @@ cdef class PeriodEngine(Int64Engine):
479480
cdef int64_t _unbox_scalar(self, scalar) except? -1:
480481
if scalar is NaT:
481482
return scalar.value
482-
if isinstance(scalar, ABCPeriod):
483+
if is_period_object(scalar):
483484
# NB: we assume that we have the correct freq here.
484485
return scalar.ordinal
485486
raise TypeError(scalar)

pandas/_libs/lib.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ from pandas._libs.tslibs.nattype cimport (
7474
from pandas._libs.tslibs.conversion cimport convert_to_tsobject
7575
from pandas._libs.tslibs.timedeltas cimport convert_to_timedelta64
7676
from pandas._libs.tslibs.timezones cimport get_timezone, tz_compare
77-
from pandas._libs.tslibs.base cimport is_period_object
77+
from pandas._libs.tslibs.period cimport is_period_object
7878

7979
from pandas._libs.missing cimport (
8080
checknull,

pandas/_libs/tslibs/base.pxd

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,3 @@ cdef class ABCTimedelta(timedelta):
66

77
cdef class ABCTimestamp(datetime):
88
pass
9-
10-
11-
cdef class ABCPeriod:
12-
pass
13-
14-
15-
cdef bint is_period_object(object obj)

pandas/_libs/tslibs/base.pyx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,3 @@ cdef class ABCTimedelta(timedelta):
1414

1515
cdef class ABCTimestamp(datetime):
1616
pass
17-
18-
19-
cdef class ABCPeriod:
20-
pass
21-
22-
23-
cdef bint is_period_object(object obj):
24-
return isinstance(obj, ABCPeriod)

pandas/_libs/tslibs/conversion.pyx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from cpython.datetime cimport (datetime, time, tzinfo,
1313
PyDateTime_IMPORT)
1414
PyDateTime_IMPORT
1515

16-
from pandas._libs.tslibs.base cimport ABCTimestamp, is_period_object
16+
from pandas._libs.tslibs.base cimport ABCTimestamp
1717

1818
from pandas._libs.tslibs.np_datetime cimport (
1919
check_dts_bounds, npy_datetimestruct, pandas_datetime_to_datetimestruct,
@@ -290,10 +290,11 @@ cdef convert_to_tsobject(object ts, object tz, object unit,
290290
# Keep the converter same as PyDateTime's
291291
ts = datetime.combine(ts, time())
292292
return convert_datetime_to_tsobject(ts, tz)
293-
elif is_period_object(ts):
294-
raise ValueError("Cannot convert Period to Timestamp "
295-
"unambiguously. Use to_timestamp")
296293
else:
294+
from .period import Period
295+
if isinstance(ts, Period):
296+
raise ValueError("Cannot convert Period to Timestamp "
297+
"unambiguously. Use to_timestamp")
297298
raise TypeError(f'Cannot convert input [{ts}] of type {type(ts)} to '
298299
f'Timestamp')
299300

pandas/_libs/tslibs/nattype.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ from pandas._libs.tslibs.np_datetime cimport (
2929
get_timedelta64_value,
3030
)
3131
cimport pandas._libs.tslibs.util as util
32-
from pandas._libs.tslibs.base cimport is_period_object
3332

3433

3534
# ----------------------------------------------------------------------
@@ -149,7 +148,7 @@ cdef class _NaT(datetime):
149148
elif util.is_offset_object(other):
150149
return c_NaT
151150

152-
elif util.is_integer_object(other) or is_period_object(other):
151+
elif util.is_integer_object(other):
153152
# For Period compat
154153
# TODO: the integer behavior is deprecated, remove it
155154
return c_NaT
@@ -163,6 +162,7 @@ cdef class _NaT(datetime):
163162
return result
164163
raise TypeError(f"Cannot add NaT to ndarray with dtype {other.dtype}")
165164

165+
# Includes Period going through here
166166
return NotImplemented
167167

168168
def __sub__(self, other):
@@ -185,7 +185,7 @@ cdef class _NaT(datetime):
185185
elif util.is_offset_object(other):
186186
return c_NaT
187187

188-
elif util.is_integer_object(other) or is_period_object(other):
188+
elif util.is_integer_object(other):
189189
# For Period compat
190190
# TODO: the integer behavior is deprecated, remove it
191191
return c_NaT
@@ -216,6 +216,7 @@ cdef class _NaT(datetime):
216216
f"Cannot subtract NaT from ndarray with dtype {other.dtype}"
217217
)
218218

219+
# Includes Period going through here
219220
return NotImplemented
220221

221222
def __pos__(self):

0 commit comments

Comments
 (0)