Skip to content
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

TypeError: unsupported operand type(s) for +: 'float' and 'decimal.Decimal' #290

Closed
Petru-Tanas-ProcessITCS opened this issue Oct 19, 2020 · 3 comments
Labels
enhancement troubleshooting Issues that seek assistance with parsing specific PDFs

Comments

@Petru-Tanas-ProcessITCS
Copy link

Petru-Tanas-ProcessITCS commented Oct 19, 2020

I am trying to extract a table from a random PDF file using explicit line, with the following table setting:

table_settings={
    "vertical_strategy": "explicit", 
    "horizontal_strategy": "explicit",
    "explicit_vertical_lines": (324, 444),
    "explicit_horizontal_lines": (333, 444),
}
im.debug_tablefinder(table_settings)

traceback:

TypeError                                 Traceback (most recent call last)
<ipython-input-33-6cb1c62ac2cf> in <module>
      5     "explicit_horizontal_lines": (333, 444),
      6 }
----> 7 im.debug_tablefinder(table_settings)

c:\costum\programs\python\lib\site-packages\pdfplumber\display.py in debug_tablefinder(self, tf)
    240             self.debug_table(table)
    241 
--> 242         self.draw_lines(tf.edges, stroke_width=1)
    243 
    244         self.draw_circles(

c:\costum\programs\python\lib\site-packages\pdfplumber\display.py in draw_lines(self, list_of_lines, **kwargs)
    128     def draw_lines(self, list_of_lines, **kwargs):
    129         for x in utils.to_list(list_of_lines):
--> 130             self.draw_line(x, **kwargs)
    131         return self
    132 

c:\costum\programs\python\lib\site-packages\pdfplumber\display.py in draw_line(self, points_or_obj, stroke, stroke_width)
    122             points = ((obj["x0"], obj["top"]), (obj["x1"], obj["bottom"]))
    123         self.draw.line(
--> 124             list(map(self._reproject, points)), fill=stroke, width=stroke_width
    125         )
    126         return self

c:\costum\programs\python\lib\site-packages\pdfplumber\display.py in _reproject(self, coord)
     99         rx0, rtop = self.root.bbox[:2]
    100         _x0 = (x0 + rx0 - px0) * self.scale
--> 101         _top = (top + rtop - ptop) * self.scale
    102         return (_x0, _top)
    103 

TypeError: unsupported operand type(s) for +: 'float' and 'decimal.Decimal'

python 3.8
windows 10
pdfplumber 0.5.23

@Petru-Tanas-ProcessITCS Petru-Tanas-ProcessITCS added the troubleshooting Issues that seek assistance with parsing specific PDFs label Oct 19, 2020
@samkit-jain
Copy link
Collaborator

Hi @Petru-Tanas-ProcessITCS. Appreciate your interest in the library. Please use the following table settings.

from decimal import Decimal

table_settings={
    "vertical_strategy": "explicit", 
    "horizontal_strategy": "explicit",
    "explicit_vertical_lines": (Decimal(324), Decimal(444)),
    "explicit_horizontal_lines": (Decimal(333), Decimal(444)),
}

im.debug_tablefinder(table_settings)

@jsvine
Copy link
Owner

jsvine commented Oct 20, 2020

Thanks, @samkit-jain — that's the correct approach for the current codebase. I think, though, that it probably makes sense to auto-decimalize the values passed for those settings, so I'm reopening this issue and adding the enhancement label.

@jsvine jsvine reopened this Oct 20, 2020
jsvine added a commit that referenced this issue Oct 20, 2020
... in TableFinder. This way, you can pass ints/floats without
pre-converting them to Decimal objects.
@jsvine
Copy link
Owner

jsvine commented Oct 20, 2020

Added this enhancement, which is now available in v0.5.24. Thanks!

@jsvine jsvine closed this as completed Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement troubleshooting Issues that seek assistance with parsing specific PDFs
Projects
None yet
Development

No branches or pull requests

3 participants