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

BUG: check_api_dict does not correctly handle tuple values #8911

Merged
merged 3 commits into from
May 5, 2017

Conversation

eric-wieser
Copy link
Member

It seems that at some point we augmented the indices with extra data. But this
data should not be included when determining uniqueness.

Previously, this would crash if there actually was a collision, rather than
printing a useful message

Copy link
Member

@njsmith njsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just me, or did the original code make no sense at all...? If we did have fully duplicate indices, wouldn't that be silently discarded before we ever made it into this function?

@eric-wieser
Copy link
Member Author

I ended up finding this because the code was detecting a duplicate index, but then crashed when trying to tell me which one it was. So the old code did work, and clearly didn't go with the transition to (ind,) over ind

Same index has been used twice in api definition: %s
""" % ['index %d -> %s' % (index, names) for index, names in doubled.items() \
if len(names) != 1]
msg = "Same index has been used twice in api definition: {}".format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might look better if this was broken into a fmt and val, and then ValueError(fmt.format(val)) or some such.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is, the format is sort of contained in val as well:

fmt = "Same index has been used twice in api definition: {}"
val = ''.join(
    '\n\tindex {} -> {}'.format(index, names)
    for index, names in doubled.items() if len(names) != 1
)
raise ValueError(fmt.format(val))

I don't think that fmt and val are useful names here, because both contain format strnigs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could do:

dupes = {index: names for index, names in doubled.items() if len(names) != 1}

raise ValueError("Same index has been used twice in api definition: {}".format(
    ''.join(
        '\n\tindex %d -> %s' % (index, names)
        for index, names in dupes.items()
    )
)

Although this is really bikeshedding, and I don't really want to switch working tree again...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing wrong with bikeshedding, code clarity is part of the process...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a preference between the one in this PR and the two alternatives above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rather like the first. Probably put the closing ) for val at the end of the preceding line there.

@charris
Copy link
Member

charris commented Apr 7, 2017

LGTM, maybe a style nit.

@charris
Copy link
Member

charris commented Apr 12, 2017

Need to finish this up.

It seems that at some point we augmented the indices with extra data. But this
data should not be included when determining uniqueness.

Previously, this would crash if there actually was a collision, rather than
printing a useful message
@eric-wieser
Copy link
Member Author

@charris: Done

@eric-wieser
Copy link
Member Author

@charris: Ping - ball is in your court now

@eric-wieser eric-wieser added this to the 1.13.0 release milestone May 5, 2017
@charris charris merged commit 8571256 into numpy:master May 5, 2017
@charris
Copy link
Member

charris commented May 5, 2017

Tnanks Eric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants