code: def _period_array_cmp(cls, op):
      
      opname = '__{name}__'.format(name=op.__name__)
      nat_result = opname == '__ne__'
  
      def wrapper(self, other):
          op = getattr(self.asi8, opname)
  
          if isinstance(other, (ABCDataFrame, ABCSeries, ABCIndexClass)):
              return NotImplemented
  
          if is_list_like(other) and len(other) != len(self):
              raise ValueError("Lengths must match")
  
          if isinstance(other, Period):
              self._check_compatible_with(other)
  
              result = op(other.ordinal)
          elif isinstance(other, cls):
              self._check_compatible_with(other)
  
              result = op(other.asi8)
  
              mask = self._isnan | other._isnan
              if mask.any():
                  result[mask] = nat_result
  
              return result
          elif other is NaT:
              result = np.empty(len(self.asi8), dtype=bool)
              result.fill(nat_result)
          else:
              other = Period(other, freq=self.freq)
              result = op(other.ordinal)
  
          if self._hasnans:
              result[self._isnan] = nat_result
  
          return result
  
      return compat.set_function_name(wrapper, opname, cls)
docs: Wrap comparison operations to convert Period-like to PeriodDtype