Skip to content

Commit 1a10666

Browse files
committed
Add exception msg
1 parent b413231 commit 1a10666

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

databricks/koalas/base.py

+31
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ def __add__(self, other) -> Union["Series", "Index"]:
330330
or isinstance(other, str)
331331
):
332332
raise TypeError("string addition can only be applied to string series or literals.")
333+
334+
if isinstance(self.spark.data_type, TimestampType):
335+
raise TypeError("addition can not be applied to date times.")
336+
333337
if isinstance(self.spark.data_type, StringType):
334338
# Concatenate string columns
335339
if isinstance(other, IndexOpsMixin) and isinstance(other.spark.data_type, StringType):
@@ -390,6 +394,9 @@ def __mul__(self, other) -> Union["Series", "Index"]:
390394
if isinstance(other, str):
391395
raise TypeError("multiplication can not be applied to a string literal.")
392396

397+
if isinstance(self.spark.data_type, TimestampType):
398+
raise TypeError("multiplication can not be applied to date times.")
399+
393400
if (
394401
isinstance(self.spark.data_type, IntegralType)
395402
and isinstance(other, IndexOpsMixin)
@@ -434,6 +441,9 @@ def __truediv__(self, other) -> Union["Series", "Index"]:
434441
):
435442
raise TypeError("division can not be applied on string series or literals.")
436443

444+
if isinstance(self.spark.data_type, TimestampType):
445+
raise TypeError("division can not be applied to date times.")
446+
437447
def truediv(left, right):
438448
return F.when(F.lit(right != 0) | F.lit(right).isNull(), left.__div__(right)).otherwise(
439449
F.when(F.lit(left == np.inf) | F.lit(left == -np.inf), left).otherwise(
@@ -451,6 +461,9 @@ def __mod__(self, other) -> Union["Series", "Index"]:
451461
):
452462
raise TypeError("modulo can not be applied on string series or literals.")
453463

464+
if isinstance(self.spark.data_type, TimestampType):
465+
raise TypeError("modulo can not be applied to date times.")
466+
454467
def mod(left, right):
455468
return ((left % right) + right) % right
456469

@@ -461,6 +474,9 @@ def __radd__(self, other) -> Union["Series", "Index"]:
461474
if not isinstance(self.spark.data_type, StringType) and isinstance(other, str):
462475
raise TypeError("string addition can only be applied to string series or literals.")
463476

477+
if isinstance(self.spark.data_type, TimestampType):
478+
raise TypeError("addition can not be applied to date times.")
479+
464480
if isinstance(self.spark.data_type, StringType):
465481
if isinstance(other, str):
466482
return self._with_new_scol(
@@ -507,6 +523,9 @@ def __rmul__(self, other) -> Union["Series", "Index"]:
507523
if isinstance(other, str):
508524
raise TypeError("multiplication can not be applied to a string literal.")
509525

526+
if isinstance(self.spark.data_type, TimestampType):
527+
raise TypeError("multiplication can not be applied to date times.")
528+
510529
if isinstance(self.spark.data_type, StringType):
511530
if isinstance(other, int):
512531
return column_op(SF.repeat)(self, other)
@@ -521,6 +540,9 @@ def __rtruediv__(self, other) -> Union["Series", "Index"]:
521540
if isinstance(self.spark.data_type, StringType) or isinstance(other, str):
522541
raise TypeError("division can not be applied on string series or literals.")
523542

543+
if isinstance(self.spark.data_type, TimestampType):
544+
raise TypeError("division can not be applied to date times.")
545+
524546
def rtruediv(left, right):
525547
return F.when(left == 0, F.lit(np.inf).__div__(right)).otherwise(
526548
F.lit(right).__truediv__(left)
@@ -552,6 +574,9 @@ def __floordiv__(self, other) -> Union["Series", "Index"]:
552574
):
553575
raise TypeError("division can not be applied on string series or literals.")
554576

577+
if isinstance(self.spark.data_type, TimestampType):
578+
raise TypeError("division can not be applied to date times.")
579+
555580
def floordiv(left, right):
556581
return F.when(F.lit(right is np.nan), np.nan).otherwise(
557582
F.when(
@@ -569,6 +594,9 @@ def __rfloordiv__(self, other) -> Union["Series", "Index"]:
569594
if isinstance(self.spark.data_type, StringType) or isinstance(other, str):
570595
raise TypeError("division can not be applied on string series or literals.")
571596

597+
if isinstance(self.spark.data_type, TimestampType):
598+
raise TypeError("division can not be applied to date times.")
599+
572600
def rfloordiv(left, right):
573601
return F.when(F.lit(left == 0), F.lit(np.inf).__div__(right)).otherwise(
574602
F.when(F.lit(left) == np.nan, np.nan).otherwise(F.floor(F.lit(right).__div__(left)))
@@ -580,6 +608,9 @@ def __rmod__(self, other) -> Union["Series", "Index"]:
580608
if isinstance(self.spark.data_type, StringType) or isinstance(other, str):
581609
raise TypeError("modulo can not be applied on string series or literals.")
582610

611+
if isinstance(self.spark.data_type, TimestampType):
612+
raise TypeError("modulo can not be applied to date times.")
613+
583614
def rmod(left, right):
584615
return ((right % left) + left) % left
585616

0 commit comments

Comments
 (0)