diff --git a/pandas/core/ops.py b/pandas/core/ops/__init__.py similarity index 98% rename from pandas/core/ops.py rename to pandas/core/ops/__init__.py index 5c58a1433ba3c..6fd53c4b24471 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops/__init__.py @@ -51,6 +51,21 @@ import pandas.core.common as com import pandas.core.missing as missing +from .roperator import ( # noqa:F401 + radd, + rand_, + rdiv, + rdivmod, + rfloordiv, + rmod, + rmul, + ror_, + rpow, + rsub, + rtruediv, + rxor, +) + # ----------------------------------------------------------------------------- # Ops Wrapping Utilities @@ -151,67 +166,6 @@ def maybe_upcast_for_op(obj): return obj -# ----------------------------------------------------------------------------- -# Reversed Operations not available in the stdlib operator module. -# Defining these instead of using lambdas allows us to reference them by name. - - -def radd(left, right): - return right + left - - -def rsub(left, right): - return right - left - - -def rmul(left, right): - return right * left - - -def rdiv(left, right): - return right / left - - -def rtruediv(left, right): - return right / left - - -def rfloordiv(left, right): - return right // left - - -def rmod(left, right): - # check if right is a string as % is the string - # formatting operation; this is a TypeError - # otherwise perform the op - if isinstance(right, str): - raise TypeError( - "{typ} cannot perform the operation mod".format(typ=type(left).__name__) - ) - - return right % left - - -def rdivmod(left, right): - return divmod(right, left) - - -def rpow(left, right): - return right ** left - - -def rand_(left, right): - return operator.and_(right, left) - - -def ror_(left, right): - return operator.or_(right, left) - - -def rxor(left, right): - return operator.xor(right, left) - - # ----------------------------------------------------------------------------- diff --git a/pandas/core/ops/roperator.py b/pandas/core/ops/roperator.py new file mode 100644 index 0000000000000..4cb02238aea16 --- /dev/null +++ b/pandas/core/ops/roperator.py @@ -0,0 +1,61 @@ +""" +Reversed Operations not available in the stdlib operator module. +Defining these instead of using lambdas allows us to reference them by name. +""" +import operator + + +def radd(left, right): + return right + left + + +def rsub(left, right): + return right - left + + +def rmul(left, right): + return right * left + + +def rdiv(left, right): + return right / left + + +def rtruediv(left, right): + return right / left + + +def rfloordiv(left, right): + return right // left + + +def rmod(left, right): + # check if right is a string as % is the string + # formatting operation; this is a TypeError + # otherwise perform the op + if isinstance(right, str): + raise TypeError( + "{typ} cannot perform the operation mod".format(typ=type(left).__name__) + ) + + return right % left + + +def rdivmod(left, right): + return divmod(right, left) + + +def rpow(left, right): + return right ** left + + +def rand_(left, right): + return operator.and_(right, left) + + +def ror_(left, right): + return operator.or_(right, left) + + +def rxor(left, right): + return operator.xor(right, left)