-
Notifications
You must be signed in to change notification settings - Fork 389
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
Fix for issue #1240. #1247
Fix for issue #1240. #1247
Conversation
Calling _str() on a tuple of expressions triggers a __repr__ call on each element, resulting in unnecessary computation. This fix detects when stringifying a tuple of exprs, and calls _str() recursively in that case.
@@ -290,6 +290,8 @@ def _str(s): | |||
return get_callable_name(s) | |||
elif isinstance(s, Node): | |||
return str(s) | |||
elif isinstance(s, (list, tuple)): | |||
return tuple(_str(x) for x in s) | |||
else: | |||
stream = StringIO() | |||
pprint(s, stream=stream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of unrelated, but the else clause is just return pformat(s).rstrip()
awesome find |
@kwmsmith Nice job! Can you add a test? Something like this: def test_str_does_not_repr():
d = Data([('aa', 1), ('b', 2)], dshape='2 * {a: string, b: int64}')
expr = transform(d, c=d.a.strlen() + d.b)
assert str(expr) == 'make sure this does not contain the repr of the underlying data' |
i'd put that in |
@cpcloud done. Pls take a look at the test -- I have a feeling there's a better way to do the |
# see GH issue #1240. | ||
d = Data([('aa', 1), ('b', 2)], dshape='2 * {a: string, b: int64}') | ||
expr = transform(d, c=d.a.strlen() + d.b) | ||
assert sub(r'_\d+', 'XXX', str(expr)) == "Merge(_child=XXX, children=(XXX, label(strlen(_child=XXX.a) + XXX.b, 'c')))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nitpick can you keep the re.sub
call style?
i also think that even though the name of the expression is an implementation detail it should be consistently numbered and therefore it'd be okay to not do the replace and just keep _1
or whatever it happens to be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of doing that, but my concern is that the _149
(I think that's the symbol) is not necessarily reproducible run-to-run, especially with py.test
running things in parallel. Is it reproducible? If so, then I'll make the replacement and remove the re.sub
call.
The generated symbol name appears to be test order dependent. When I run the standard testsuite command (
And:
|
Can you explicitly name the interactive symbol? Does the |
@llllllllll thanks for pointing that out, it works great. |
@kwmsmith Thanks for finding and fixing this! |
@cpcloud @llllllllll I'm glad we got it fixed and that the fix itself was straightforward. Thanks for your help! |
Calling
_str()
on a tuple of expressions triggers a__repr__
call oneach element, resulting in unnecessary computation.
This fix detects when stringifying a tuple of exprs, and calls
_str()
recursively in that case.