Skip to content

Commit a874f5f

Browse files
committed
na in unbox
1 parent b2afd4e commit a874f5f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ def _get_attributes_dict(self):
8989

9090
@property
9191
def _scalar_type(self):
92+
# type: () -> Union[type, Tuple[type]]
9293
"""The scalar associated with this datelike
9394
9495
* PeriodArray : Period
9596
* DatetimeArray : Timestamp
9697
* TimedeltaArray : Timedelta
9798
"""
98-
# type: # () -> Union[type, Tuple[type]]
9999
raise AbstractMethodError(self)
100100

101101
def _scalar_from_string(self, value):
102-
# type: (str) -> Union[Period, Timestamp, Timedelta, NaT]
102+
# type: (str) -> Union[Period, Timestamp, Timedelta, NaTType]
103103
"""
104104
Construct a scalar type from a string.
105105
@@ -120,6 +120,7 @@ def _scalar_from_string(self, value):
120120
raise AbstractMethodError(self)
121121

122122
def _unbox_scalar(self, value):
123+
# type: (Union[Period, Timestamp, Timedelta, NaTType]) -> int
123124
"""
124125
Unbox the integer value of a scalar `value`.
125126
@@ -139,6 +140,9 @@ def _unbox_scalar(self, value):
139140
raise AbstractMethodError(self)
140141

141142
def _check_compatible_with(self, other):
143+
# TODO: choose a type for other
144+
# Can it be NaT?
145+
# Scalar, array, or both?
142146
"""
143147
Verify that `self` and `other` are compatible.
144148

pandas/core/arrays/datetimes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ def _generate_range(cls, start, end, periods, freq, tz=None,
439439
def _unbox_scalar(self, value):
440440
if not isinstance(value, (self._scalar_type, type(NaT))):
441441
raise ValueError("'value' should be a a Timestamp..")
442-
self._check_compatible_with(value)
442+
if not isna(value):
443+
self._check_compatible_with(value)
443444
return value.value
444445

445446
def _scalar_from_string(self, value):

pandas/core/arrays/period.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def _unbox_scalar(self, value):
240240
if value is NaT:
241241
return value.value
242242
elif isinstance(value, self._scalar_type):
243-
self._check_compatible_with(value)
243+
if not isna(value):
244+
self._check_compatible_with(value)
244245
return value.ordinal
245246
else:
246247
msg = (

0 commit comments

Comments
 (0)