Skip to content

Commit

Permalink
Add pandas analysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-matera committed May 17, 2023
1 parent beb5eca commit 5ec8dec
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Packages/p4e/testlib.py
Expand Up @@ -22,6 +22,7 @@
import pathlib
import subprocess
import inspect
import pandas

from contextlib import contextmanager
from pathlib import Path
Expand Down Expand Up @@ -299,7 +300,6 @@ def tearDown(self):
@unittest.skipUnless(os.environ.get('TESTER_NO_SYNTAX') is None, None)
def testzz_1_ast(self):
"""Testing solution syntax."""

req = set()
banned = set()
if hasattr(self, 'tokens_required'):
Expand All @@ -311,9 +311,9 @@ def testzz_1_ast(self):
nodes = list(ast.walk(ast.parse(self.source_code)))
types = {x.__class__ for x in nodes}
for node in req - types:
self.fail(f"This answer requires Python syntax: {node}")
self.fail(f"The function '{self.test_hasattr}' requires {node}.")
for node in banned & types:
self.fail(f"You used forbidden Python syntax: {node}")
self.fail(f"You cannot use {node} in the '{self.test_hasattr}' function.")

@unittest.skipIf(os.environ.get('TESTER_GPT') is None, None)
def testzz_2_gpt(self):
Expand Down Expand Up @@ -512,6 +512,20 @@ def _compare(self, got, exp):
if got is not None:
return f"""The value should be None"""

elif isinstance(exp, pandas.DataFrame):
try:
if len(exp.compare(got)) != 0:
return f"""The DataFrame:\n{got}\n doesn't match the expected Series:\n{exp}\n"""
except ValueError as e:
return f"""The DataFrame:\n{got}\n doesn't match the expected Series:\n{exp}\n"""

elif isinstance(exp, pandas.Series):
try:
if len(exp.compare(got)) != 0:
return f"""The Series:\n{got}\n doesn't match the expected Series:\n{exp}\n"""
except ValueError as e:
return f"""The Series:\n{got}\n doesn't match the expected Series:\n{exp}\n"""

else:
raise ValueError("The compare function doesn't work on this type:", exp.__class__.__name__)

Expand Down

0 comments on commit 5ec8dec

Please sign in to comment.