question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RecursionError: maximum recursion depth exceeded in comparison for Decimal.quantize()

See original GitHub issue

I’m getting an endless loop which seems to be triggered by Decimal.quantize() calling RP2Decimal.__ne__ which then calls RP2Decimal.__eq__ which then calls Decimal.quantize() again.

I presume there is something wrong with my numbers, which I have yet to investigate.

...
  File "/home/rndstr/venv3/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 40, in __eq__
    return (self - other).quantize(CRYPTO_DECIMAL_MASK).__eq__(ZERO)
  File "/usr/lib/python3.10/_pydecimal.py", line 2588, in quantize
    if ans != self:
  File "/home/rndstr/venv3/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 43, in __ne__
    return not self.__eq__(other)
  File "/home/rndstr/venv3/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 40, in __eq__
    return (self - other).quantize(CRYPTO_DECIMAL_MASK).__eq__(ZERO)
  File "/usr/lib/python3.10/_pydecimal.py", line 2588, in quantize
    if ans != self:
  File "/home/rndstr/venv3/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 43, in __ne__
    return not self.__eq__(other)
  File "/home/rndstr/venv3/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 40, in __eq__
    return (self - other).quantize(CRYPTO_DECIMAL_MASK).__eq__(ZERO)
  File "/home/rndstr/venv3/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 69, in __sub__
    return RP2Decimal(Decimal.__sub__(self, other))
  File "/usr/lib/python3.10/_pydecimal.py", line 1257, in __sub__
    return self.__add__(other.copy_negate(), context=context)
  File "/home/rndstr/venv3/lib/python3.10/site-packages/rp2/rp2_decimal.py", line 64, in __add__
    return RP2Decimal(Decimal.__add__(self, other))
  File "/usr/lib/python3.10/_pydecimal.py", line 1202, in __add__
    ans = self._rescale(exp, context.rounding)
  File "/usr/lib/python3.10/_pydecimal.py", line 2625, in _rescale
    if not self:
  File "/usr/lib/python3.10/_pydecimal.py", line 815, in __bool__
    return self._is_special or self._int != '0'
RecursionError: maximum recursion depth exceeded in comparison

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rndstrcommented, Apr 17, 2022

I ended up running it with Docker where it works, posting as it may help others running into the same issue:

Create Dockerfile

FROM python:3.9
WORKDIR /usr/src/app
RUN pip3 install rp2

In same dir run

docker build --tag rp2 

Go to your directory with input.ods and input.config files, run

docker run -it --rm --name rp2-script -v "$PWD":/usr/src/app -w /usr/src/app rp2 rp2_us input.config input.ods
0reactions
eprbellcommented, Apr 13, 2022

I tried your files and they worked on my machine:

> rp2_us loop.config loop.ods
 
INFO: Country: us
INFO: Accounting Method: fifo
INFO: Configuration file: loop.config
INFO: Input file: loop.ods
INFO: Processing ETH
INFO: Generating output for plugin 'rp2.plugin.report.rp2_full_report'
INFO: Plugin 'rp2.plugin.report.rp2_full_report' output: /private/tmp/output/fifo_rp2_full_report.ods
INFO: Generating output for plugin 'rp2.plugin.report.us.tax_report_us'
INFO: Plugin 'rp2.plugin.report.us.tax_report_us' output: /private/tmp/output/fifo_tax_report_us.ods
INFO: Log file: ./log/rp2_2022_04_12_21_22_19_512993.log
INFO: Generated output directory: output/
INFO: Done

I wonder if other Python packages using Decimal and high-precision math work on your machine: it might be an experiment worth trying.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the maximum recursion depth in Python, and how to ...
It works up to n=997 , then it just breaks and spits out a RecursionError: maximum recursion depth exceeded in comparison . Is...
Read more >
maximum recursion depth exceeded while calling a Python ...
RecursionError : maximum recursion depth exceeded in comparison ... We have created a function named nested() which accepts one argument – n.
Read more >
Python RecursionError: Maximum Recursion Depth Exceeded ...
RecursionError : Maximum Recursion Depth Exceeded in Comparison. Let's create a program to calculate the factorial of a number following the ...
Read more >
json.dumps() lacks information about RecursionError related ...
'0' RecursionError: maximum recursion depth exceeded in comparison Details: I have encountered issue when porting my code from Python 2 to 3 ...
Read more >
Python maximum recursion depth exceeded in comparison
The Solution. Python has raised a recursion error to protect us against a stack overflow. This is when the pointer in a stack...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found