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

[REF] slow np.isclose to math.isclose #166

Merged
merged 1 commit into from
Oct 14, 2024
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
10 changes: 5 additions & 5 deletions camelot/parsers/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Defines a base parser. As well as generic methods for other parsers."""

import math
import os
import warnings

import numpy as np
import pandas as pd

from ..core import Table
Expand Down Expand Up @@ -319,7 +319,7 @@ def _group_rows(text, row_tol=2):
# if type(obj) is LTChar]):
if row_y is None:
row_y = t.y0
elif not np.isclose(row_y, t.y0, atol=row_tol):
elif not math.isclose(row_y, t.y0, abs_tol=row_tol):
rows.append(sorted(temp, key=lambda t: t.x0))
temp = []
# We update the row's bottom as we go, to be forgiving if there
Expand Down Expand Up @@ -352,8 +352,8 @@ def _merge_columns(cl, column_tol=0):
else:
lower = merged[-1]
if column_tol >= 0:
if higher[0] <= lower[1] or np.isclose(
higher[0], lower[1], atol=column_tol
if higher[0] <= lower[1] or math.isclose(
higher[0], lower[1], abs_tol=column_tol
):
upper_bound = max(lower[1], higher[1])
lower_bound = min(lower[0], higher[0])
Expand All @@ -362,7 +362,7 @@ def _merge_columns(cl, column_tol=0):
merged.append(higher)
elif column_tol < 0:
if higher[0] <= lower[1]:
if np.isclose(higher[0], lower[1], atol=abs(column_tol)):
if math.isclose(higher[0], lower[1], abs_tol=abs(column_tol)):
merged.append(higher)
else:
upper_bound = max(lower[1], higher[1])
Expand Down
3 changes: 2 additions & 1 deletion camelot/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""General helper utilities to parse the pdf tables."""

import atexit
import math
import os
import random
import re
Expand Down Expand Up @@ -855,7 +856,7 @@ def merge_close_lines(ar, line_tol=2):
ret.append(a)
else:
temp = ret[-1]
if np.isclose(temp, a, atol=line_tol):
if math.isclose(temp, a, abs_tol=line_tol):
temp = (temp + a) / 2.0
ret[-1] = temp
else:
Expand Down