Skip to content

REF: make ops a directory #27238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 15 additions & 61 deletions pandas/core/ops.py → pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)


# -----------------------------------------------------------------------------


Expand Down
61 changes: 61 additions & 0 deletions pandas/core/ops/roperator.py
Original file line number Diff line number Diff line change
@@ -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)