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

C++ refactoring: Make highlevel __repr__ safe for typetracers. #1218

Merged
merged 1 commit into from
Jan 13, 2022
Merged
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
27 changes: 21 additions & 6 deletions src/awkward/_v2/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,14 +1247,20 @@ def __repr__(self):
import awkward._v2._prettyprint

pytype = type(self).__name__
valuestr = awkward._v2._prettyprint.valuestr(self, 1, 50)
if self._layout.nplike.known_shape and self._layout.nplike.known_data:
valuestr = " " + awkward._v2._prettyprint.valuestr(self, 1, 50)
typestr = repr(str(self.type))[1:-1]
else:
valuestr = "-typetracer"
typestr = repr(
"?? * " + str(self._layout.form.type_from_behavior(self._behavior))
)[1:-1]
length = max(10, 80 - len(pytype) - 10 - len(valuestr))
typestr = repr(str(self.type))[1:-1]
if len(typestr) > length:
typestr = "'" + typestr[: length - 3] + "...'"
else:
typestr = "'" + typestr + "'"
return "<{0} {1} type={2}>".format(pytype, valuestr, typestr)
return "<{0}{1} type={2}>".format(pytype, valuestr, typestr)

def show(self, limit_rows=20, limit_cols=80, type=False, stream=sys.stdout):
"""
Expand Down Expand Up @@ -1933,14 +1939,23 @@ def __repr__(self):
import awkward._v2._prettyprint

pytype = type(self).__name__
valuestr = awkward._v2._prettyprint.valuestr(self, 1, 50)
if (
self._layout.array.nplike.known_shape
and self._layout.array.nplike.known_data
):
valuestr = " " + awkward._v2._prettyprint.valuestr(self, 1, 50)
typestr = repr(str(self.type))[1:-1]
else:
valuestr = "-typetracer"
typestr = repr(
str(self._layout.array.form.type_from_behavior(self._behavior))
)[1:-1]
length = max(10, 80 - len(pytype) - 10 - len(valuestr))
typestr = repr(str(self.type))[1:-1]
if len(typestr) > length:
typestr = "'" + typestr[: length - 3] + "...'"
else:
typestr = "'" + typestr + "'"
return "<{0} {1} type={2}>".format(pytype, valuestr, typestr)
return "<{0}{1} type={2}>".format(pytype, valuestr, typestr)

def show(self, limit_rows=20, limit_cols=80, type=False, stream=sys.stdout):
"""
Expand Down