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

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

31 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 

9from typing import Any 

10 

11 

12def radd(left: Any, right: Any) -> Any: 

13 return right + left 

14 

15 

16def rsub(left: Any, right: Any) -> Any: 

17 return right - left 

18 

19 

20def rmul(left: Any, right: Any) -> Any: 

21 return right * left 

22 

23 

24def rdiv(left: Any, right: Any) -> Any: 

25 return right / left 

26 

27 

28def rtruediv(left: Any, right: Any) -> Any: 

29 return right / left 

30 

31 

32def rfloordiv(left: Any, right: Any) -> Any: 

33 return right // left 

34 

35 

36def rmod(left: Any, right: Any) -> Any: 

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

38 # formatting operation; this is a TypeError 

39 # otherwise perform the op 

40 if isinstance(right, str): 

41 typ = type(left).__name__ 

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

43 

44 return right % left 

45 

46 

47def rdivmod(left: Any, right: Any) -> tuple[Any, Any]: 

48 return divmod(right, left) 

49 

50 

51def rpow(left: Any, right: Any) -> Any: 

52 return right**left 

53 

54 

55def rand_(left: Any, right: Any) -> Any: 

56 return operator.and_(right, left) 

57 

58 

59def ror_(left: Any, right: Any) -> Any: 

60 return operator.or_(right, left) 

61 

62 

63def rxor(left: Any, right: Any) -> Any: 

64 return operator.xor(right, left)