8000 CLN: trim unnecessary code in indexing tests by jbrockmendel · Pull Request #29845 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CLN: trim unnecessary code in indexing tests #29845

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

Merged
merged 9 commits into from
Nov 27, 2019
Prev Previous commit
Next Next commit
remove _print method
  • Loading branch information
jbrockmendel committed Nov 25, 2019
commit 9dcc2ac37167ddeed1fd4e3a90fce5c57aa32322
30 changes: 5 additions & 25 deletions pandas/tests/indexing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,13 @@ def check_values(self, f, func, values=False):
tm.assert_almost_equal(result, expected)

def check_result(
self,
method1,
key1,
method2,
key2,
typs=None,
axes=None,
fails=None,
self, method1, key1, method2, key2, typs=None, axes=None, fails=None,
):
def _eq(typ, kind, axis, obj, key1, key2):
def _eq(axis, obj, key1, key2):
""" compare equal for these 2 keys """
if axis > obj.ndim - 1:
return

def _print(result, error=None):
err = str(error) if error is not None else ""
msg = (
"[%-16.16s]: [typ->%-8.8s,obj->%-8.8s,"
"key1->(%-4.4s),key2->(%-4.4s),axis->%s] %s"
% (result, typ, kind, method1, method2, axis, err)
)

try:
rs = getattr(obj, method1).__getitem__(_axify(obj, key1, axis))

Expand All @@ -207,7 +192,6 @@ def _print(result, error=None):
except (KeyError, IndexError):
# TODO: why is this allowed?
result = "no comp"
_print(result)
return

detail = None
Expand All @@ -227,23 +211,19 @@ def _print(result, error=None):
if result == "fail":
result = "ok (fail)"

_print(result)
if not result.startswith("ok"):
raise AssertionError(detail)

except AssertionError:
raise
except (IndexError, TypeError, KeyError) as detail:

# if we are in fails, the ok, otherwise raise it
if fails is not None:
if isinstance(detail, fails):
result = "ok ({0.__name__})".format(type(detail))
_print(result)
result = f"ok ({type(detail).__name__})"
return

result = type(detail).__name__
raise AssertionError(_print(result, error=detail))
raise AssertionError(result, detail)

if typs is None:
typs = self._typs
Expand All @@ -264,4 +244,4 @@ def _print(result, error=None):
continue

obj = d[typ]
_eq(typ=typ, kind=kind, axis=ax, obj=obj, key1=key1, key2=key2)
_eq(axis=ax, obj=obj, key1=key1, key2=key2)
0