From 7939d9393795df89af300da2e8d917e676048851 Mon Sep 17 00:00:00 2001 From: makbigc Date: Tue, 18 Dec 2018 19:35:49 +0800 Subject: [PATCH] Add _validate_shape --- pandas/core/arrays/base.py | 4 ++++ pandas/core/arrays/period.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index cf145064fd7b17..a9be23a4afc2f5 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -862,6 +862,10 @@ def _add_comparison_ops(cls): cls.__le__ = cls._create_comparison_method(operator.le) cls.__ge__ = cls._create_comparison_method(operator.ge) + def _validate_shape(self, other): + if len(self) != len(other): + raise ValueError('Lengths must match to compare') + class ExtensionScalarOpsMixin(ExtensionOpsMixin): """ diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 42a4a02923bbd5..8409c0da2216f5 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -68,8 +68,7 @@ def wrapper(self, other): elif isinstance(other, cls): self._check_compatible_with(other) - if other.ndim > 0 and len(self) != len(other): - raise ValueError('Lengths must match to compare') + self._validate_shape(other) if not_implemented: return NotImplemented