Skip to content

Commit

Permalink
Remove pandas from dev requirements and tests
Browse files Browse the repository at this point in the history
Results in needing one more # pragma: nocover statement, but on a
simple line of code. See PR #253 for details and motivation.
  • Loading branch information
jsvine committed Aug 15, 2020
1 parent 90f767f commit a5e7d7f
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 162 deletions.
2 changes: 1 addition & 1 deletion pdfplumber/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def is_dataframe(collection):

def to_list(collection):
if is_dataframe(collection):
return collection.to_dict("records")
return collection.to_dict("records") # pragma: nocover
else:
return list(collection)

Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pandas>=1.0.0
pytest
pytest-cov
pytest-parallel
Expand Down
Binary file modified tests/pdfs/pdffill-demo.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion tests/test_basics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import unittest
import pytest
import pandas as pd
import pdfplumber
import sys, os

Expand Down
3 changes: 1 addition & 2 deletions tests/test_ca_warn_report.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import unittest
import pandas as pd
import pdfplumber
from pdfplumber import utils
from pdfplumber import table
Expand Down Expand Up @@ -37,7 +36,7 @@ def test_objects(self):
assert len(self.pdf.figures)
assert len(self.pdf.images)

def test_pandas(self):
def test_parse(self):

rect_x0_clusters = utils.cluster_list([ r["x0"]
for r in self.pdf.pages[1].rects ], tolerance=3)
Expand Down
1 change: 0 additions & 1 deletion tests/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import unittest
import pytest
import pandas as pd
import pdfplumber
from subprocess import Popen, PIPE
from io import StringIO
Expand Down
1 change: 0 additions & 1 deletion tests/test_display.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import unittest
import pandas as pd
import pdfplumber
import sys, os, io

Expand Down
1 change: 0 additions & 1 deletion tests/test_issues.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import unittest
import pandas as pd
import pdfplumber
import sys, os
import six
Expand Down
121 changes: 0 additions & 121 deletions tests/test_la_precinct_bulletin.py

This file was deleted.

31 changes: 0 additions & 31 deletions tests/test_nics_report.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import unittest
import pandas as pd
import pdfplumber
from operator import itemgetter
from pdfplumber.utils import within_bbox, collate_chars
Expand Down Expand Up @@ -86,36 +85,6 @@ def parse_row(row):
month_text = collate_chars(month_chars)
assert(month_text == "November - 2015")

def test_pandas(self):
page = self.pdf.pages[0]
cropped = page.crop((0, 80, self.PDF_WIDTH, 485))
table = cropped.extract_table({
"horizontal_strategy": "text",
"explicit_vertical_lines": [
min(map(itemgetter("x0"), cropped.chars))
],
"intersection_tolerance": 5
})

table = pd.DataFrame(table)

def parse_value(x):
if pd.isnull(x) or x == "": return None
return int(x.replace(",", ""))

table.columns = COLUMNS
table[table.columns[1:]] = table[table.columns[1:]].applymap(parse_value)

# [1:] because first column is state name
for c in COLUMNS[1:]:
total = table[c].iloc[-1]
colsum = table[c].sum()
assert(colsum == (total * 2))

month_chars = within_bbox(page.chars, (0, 35, self.PDF_WIDTH, 65))
month_text = collate_chars(month_chars)
assert(month_text == "November - 2015")

def test_filter(self):
page = self.pdf.pages[0]
def test(obj):
Expand Down
1 change: 0 additions & 1 deletion tests/test_table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import unittest
import pytest
import pandas as pd
import pdfplumber
from pdfplumber import table
import sys, os
Expand Down
50 changes: 49 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import unittest
import pytest
import pandas as pd
import pdfplumber
from pdfplumber import utils
from pdfminer.pdfparser import PDFObjRef
Expand Down Expand Up @@ -98,6 +97,55 @@ def test_extract_text(self):
assert text == goal
assert self.pdf.pages[0].crop((0, 0, 1, 1)).extract_text() == None

def test_intersects_bbox(self):
objs = [
# Is same as bbox
{
"x0": 0,
"top": 0,
"x1": 20,
"bottom": 20,
},
# Inside bbox
{
"x0": 10,
"top": 10,
"x1": 15,
"bottom": 15,
},
# Overlaps bbox
{
"x0": 10,
"top": 10,
"x1": 30,
"bottom": 30,
},
# Touching on one side
{
"x0": 20,
"top": 0,
"x1": 40,
"bottom": 20,
},
# Touching on one corner
{
"x0": 20,
"top": 20,
"x1": 40,
"bottom": 40,
},
# Fully outside
{
"x0": 21,
"top": 21,
"x1": 40,
"bottom": 40,
},
]
bbox = utils.obj_to_bbox(objs[0])

assert utils.intersects_bbox(objs, bbox) == objs[:4]

def test_resize_object(self):
obj = {
"x0": 5,
Expand Down

0 comments on commit a5e7d7f

Please sign in to comment.