Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pandas/core/roperator.py: 50%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

30 statements  

1""" 

2Reversed Operations not available in the stdlib operator module. 

3Defining these instead of using lambdas allows us to reference them by name. 

4""" 

5 

6from __future__ import annotations 

7 

8import operator 

9 

10 

11def radd(left, right): 

12 return right + left 

13 

14 

15def rsub(left, right): 

16 return right - left 

17 

18 

19def rmul(left, right): 

20 return right * left 

21 

22 

23def rdiv(left, right): 

24 return right / left 

25 

26 

27def rtruediv(left, right): 

28 return right / left 

29 

30 

31def rfloordiv(left, right): 

32 return right // left 

33 

34 

35def rmod(left, right): 

36 # check if right is a string as % is the string 

37 # formatting operation; this is a TypeError 

38 # otherwise perform the op 

39 if isinstance(right, str): 

40 typ = type(left).__name__ 

41 raise TypeError(f"{typ} cannot perform the operation mod") 

42 

43 return right % left 

44 

45 

46def rdivmod(left, right): 

47 return divmod(right, left) 

48 

49 

50def rpow(left, right): 

51 return right**left 

52 

53 

54def rand_(left, right): 

55 return operator.and_(right, left) 

56 

57 

58def ror_(left, right): 

59 return operator.or_(right, left) 

60 

61 

62def rxor(left, right): 

63 return operator.xor(right, left)