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

add guidelines for testing dicts to devel guide #17362

Closed
kcrisman opened this issue Nov 18, 2014 · 11 comments
Closed

add guidelines for testing dicts to devel guide #17362

kcrisman opened this issue Nov 18, 2014 · 11 comments

Comments

@kcrisman
Copy link
Member

The developer guide doesn't mention that dictionaries can come out platform-dependent or worse in Python. New developers should have a good place to find a good example or two of how to deal with this.

Component: documentation

Reviewer: Jeroen Demeyer, Karl-Dieter Crisman

Issue created by migration from https://trac.sagemath.org/ticket/17362

@kcrisman kcrisman added this to the sage-6.5 milestone Nov 18, 2014
@kcrisman

This comment has been minimized.

@kcrisman
Copy link
Member Author

comment:2

E.g. something along the lines of

sage: D = {1:2, 2:3} # possibly random order depending on hashing
sage: E = {2:3, 1:2}
sage: sorted(D.items()) # guaranteed
[(1, 2), (2, 3)]
sage: sorted(E.items()) == sorted(D.items())
True

but perhaps someone might have an actual example that had to be fixed for the Sage doc to test right, I am pretty sure Trac is full of these.

@jdemeyer
Copy link

Replying to @kcrisman:

dictionaries can come out platform-dependent or worse in Python.

Isn't this fixed by #16746?

@kcrisman
Copy link
Member Author

comment:4

dictionaries can come out platform-dependent or worse in Python.

Isn't this fixed by #16746?

I didn't know about that aspect of it, only the graphics part. So will doctests automatically fail if people put them in the order that their computer gives and it's not sorted? That could be confusing! So maybe it should still be mentioned in the guide, along with the graphics piece - which is not what the command line gives.

And, more relevant to my immediate concern, what if the keys themselves are dictionary-enough that they are platform-dependent? See #16331 for an explicit example of this. It would be great if you could give some advice for that, because we haven't come to any useful consensus yet.

@jdemeyer
Copy link

comment:5

Replying to @kcrisman:

So will doctests automatically fail if people put them in the order that their computer gives and it's not sorted?

There are 2 dict orders: the Python order and the IPython order. The Python order is what you get with print statements, the IPython order is the sorted order. The latter is used by the IPython interface, by sagenb and by doctests. So, I would say that the order in doctests after #16746 is actually the order that "their computer gives".

@jdemeyer
Copy link

comment:6

Replying to @kcrisman:

And, more relevant to my immediate concern, what if the keys themselves are dictionary-enough that they are platform-dependent? See #16331 for an explicit example of this. It would be great if you could give some advice for that, because we haven't come to any useful consensus yet.

Well, #16331 is special because you're sorting a list containing integers and strings. The problem is that the output of sorted([3,"foo"]) isn't well-defined.

@kcrisman
Copy link
Member Author

comment:7

And, more relevant to my immediate concern, what if the keys themselves are dictionary-enough that they are platform-dependent? See #16331 for an explicit example of this. It would be great if you could give some advice for that, because we haven't come to any useful consensus yet.

Well, #16331 is special because you're sorting a list containing integers and strings. The problem is that the output of sorted([3,"foo"]) isn't well-defined.

Yikes, and apparently isn't even allowed in Python 3.

the IPython order is the sorted order.

Hmm, although I still think some updating could be done, I guess a ticket just for that or the graphics thing, which is now everywhere, probably isn't that worthwhile.

@jdemeyer
Copy link

comment:8

Close as "wontfix"?

@jdemeyer jdemeyer removed this from the sage-6.5 milestone Nov 19, 2014
@kcrisman
Copy link
Member Author

comment:9

ok

@jdemeyer
Copy link

Reviewer: Karl-Dieter Crisman

@kcrisman
Copy link
Member Author

Changed reviewer from Karl-Dieter Crisman to Jeroen Demeyer, Karl-Dieter Crisman

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

No branches or pull requests

3 participants