Re: display of dicts?

Chris Barker <[email protected]> Mon, 18 Dec 2017 20:19:57 -0800
Newsgroups gmane.comp.python.ipython.devel
Message-ID <CALGmxEJwAgKose6_NwS9PojPd=rLNam73gB3ucqKsxiMNhZ0+w@mail.gmail.com>
--===============0916086148418846209==
Content-Type: multipart/alternative; boundary="94eb2c1f2df4fff56a0560a9c954"

--94eb2c1f2df4fff56a0560a9c954
Content-Type: text/plain; charset="UTF-8"

On Mon, Dec 18, 2017 at 7:04 PM, Nathan Goldbaum <[email protected]>
wrote:

> Nope, I believe it's this: https://github.com/ipython/ipython/blob/
> dc9d1c679424589480bb83af64aa5ee21031d311/IPython/lib/pretty.py
>

I see, thanks! Though it does have the same behavior of sorting dicts --
you can see that in:

``_dict_pprinter_factory``

However as of cPYthon 3.6, and officially as of 3.7, dicts will maintain
their insertion order.

So we should probably remove the sorting from the _dict_pprinter_factory.

-CHB




>
>
> On Mon, Dec 18, 2017 at 7:56 PM, Chris Barker <[email protected]>
> wrote:
>
>> Thanks Nathan,
>>
>> And to confirm, this is the stdlib's pprint module, yes?
>>
>> (which does seem to show the same behavior)
>>
>> -CHB
>>
>>
>>
>> On Mon, Dec 18, 2017 at 5:40 PM, Nathan Goldbaum <[email protected]>
>> wrote:
>>
>>> IPython does use pretty-printing by default. You can control it with the
>>> %pprint magic, in your IPython configuration, with the
>>> PlainTextFormatter.pprint option, or with the --pprint command line
>>> argument when starting IPython.
>>>
>>> http://ipython.readthedocs.io/en/stable/config/options/termi
>>> nal.html#configtrait-PlainTextFormatter.pprint
>>>
>>>
>>>
>>> On Mon, Dec 18, 2017 at 7:08 PM, Chris Barker <[email protected]>
>>> wrote:
>>>
>>>> As Guido has just declared that dicts will now officially preserve
>>>> order:
>>>>
>>>> https://mail.python.org/pipermail/python-dev/2017-December/151283.html
>>>>
>>>> I was playing around  them in py3.6 ipython, and found some (to me) odd
>>>> behavior:
>>>>
>>>> In [1]: d = {'one':1, 'two':2, 'three':3}
>>>>
>>>> In [2]: d
>>>> Out[2]: {'one': 1, 'three': 3, 'two': 2}
>>>>
>>>> Hmm -- order does not appear to be preserved.
>>>>
>>>> But then:
>>>>
>>>> In [3]: str(d)
>>>> Out[3]: "{'one': 1, 'two': 2, 'three': 3}"
>>>>
>>>> In [4]: repr(d)
>>>> Out[4]: "{'one': 1, 'two': 2, 'three': 3}"
>>>>
>>>> In [5]: d.values()
>>>> Out[5]: dict_values([1, 2, 3])
>>>>
>>>> In [6]: d.keys()
>>>> Out[6]: dict_keys(['one', 'two', 'three'])
>>>>
>>>> In [7]: d.items()
>>>> Out[7]: dict_items([('one', 1), ('two', 2), ('three', 3)])
>>>>
>>>> Order IS preserved.
>>>>
>>>> So presumably iPython is calling sorted() or some such when displaying
>>>> a dict.
>>>>
>>>> Is that that case? Is that documented anywhere?? I can't find it.
>>>>
>>>> And with Python >= 3.6, dict order is preserved, so it would probably
>>>> be better to NOT mess with dict order when displaying them in iPython.
>>>>
>>>> SIDE NOTE:
>>>>
>>>> I had a bit of trouble finding this mailing list -- google still points
>>>> to the old ones on scipy.org. -- maybe we can put a note on the home
>>>> page of those lists that they are been moved??
>>>>
>>>> (I only noticed, 'cause the archives of those stop last March)
>>>>
>>>> -Chris
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Christopher Barker, Ph.D.
>>>> Oceanographer
>>>>
>>>> Emergency Response Division
>>>> NOAA/NOS/OR&R            (206) 526-6959   voice
>>>> 7600 Sand Point Way NE   (206) 526-6329   fax
>>>> Seattle, WA  98115       (206) 526-6317   main reception
>>>>
>>>> [email protected]
>>>>
>>>> _______________________________________________
>>>> IPython-dev mailing list
>>>> [email protected]
>>>> https://mail.python.org/mailman/listinfo/ipython-dev
>>>>
>>>>
>>>
>>> _______________________________________________
>>> IPython-dev mailing list
>>> [email protected]
>>> https://mail.python.org/mailman/listinfo/ipython-dev
>>>
>>>
>>
>>
>> --
>>
>> Christopher Barker, Ph.D.
>> Oceanographer
>>
>> Emergency Response Division
>> NOAA/NOS/OR&R            (206) 526-6959   voice
>> 7600 Sand Point Way NE   (206) 526-6329   fax
>> Seattle, WA  98115       (206) 526-6317   main reception
>>
>> [email protected]
>>
>> _______________________________________________
>> IPython-dev mailing list
>> [email protected]
>> https://mail.python.org/mailman/listinfo/ipython-dev
>>
>>
>
> _______________________________________________
> IPython-dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/ipython-dev
>
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]

--94eb2c1f2df4fff56a0560a9c954
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Mon, Dec 18, 2017 at 7:04 PM, Nathan Goldbaum <span dir=3D"ltr">&lt;=
<a href=3D"mailto:[email protected]" target=3D"_blank">nathan12343@gmai=
l.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left=
:1ex"><div dir=3D"ltr">Nope, I believe it&#39;s this: <a href=3D"https://gi=
thub.com/ipython/ipython/blob/dc9d1c679424589480bb83af64aa5ee21031d311/IPyt=
hon/lib/pretty.py" target=3D"_blank">https://github.com/ipython/<wbr>ipytho=
n/blob/<wbr>dc9d1c679424589480bb83af64aa5e<wbr>e21031d311/IPython/lib/prett=
y.<wbr>py</a></div></blockquote><div><br></div><div>I see, thanks! Though i=
t does have the same behavior of sorting dicts -- you can see that in:<br><=
br><span class=3D"gmail-pl-en">``_dict_pprinter_factory``</span></div><div>=
<br></div><div>However as of cPYthon 3.6, and officially as of 3.7, dicts w=
ill maintain their insertion order.<br><br></div><div>So we should probably=
 remove the sorting from the <span class=3D"gmail-pl-en">_dict_pprinter_fac=
tory.<br><br></span></div><div><span class=3D"gmail-pl-en">-CHB<br><br></sp=
an></div><div><br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:=
1ex"><div dir=3D"ltr"><br></div><div class=3D"gmail-HOEnZb"><div class=3D"g=
mail-h5"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Mon, =
Dec 18, 2017 at 7:56 PM, Chris Barker <span dir=3D"ltr">&lt;<a href=3D"mail=
to:[email protected]" target=3D"_blank">[email protected]</a>&gt;</=
span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0=
px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=
=3D"ltr"><div><div><div>Thanks Nathan,<br><br></div>And to confirm, this is=
 the stdlib&#39;s pprint module, yes?<br><br></div>(which does seem to show=
 the same behavior)<br><br></div>-CHB<br><br><div><div><br></div></div></di=
v><div class=3D"gmail-m_-3730345828008721064HOEnZb"><div class=3D"gmail-m_-=
3730345828008721064h5"><div class=3D"gmail_extra"><br><div class=3D"gmail_q=
uote">On Mon, Dec 18, 2017 at 5:40 PM, Nathan Goldbaum <span dir=3D"ltr">&l=
t;<a href=3D"mailto:[email protected]" target=3D"_blank">nathan12343@gm=
ail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex"><div dir=3D"ltr">IPython does use pretty-printing by default. You c=
an control it with the %pprint magic, in your IPython configuration, with t=
he PlainTextFormatter.pprint option, or with the --pprint command line argu=
ment when starting IPython.<br><br><a href=3D"http://ipython.readthedocs.io=
/en/stable/config/options/terminal.html#configtrait-PlainTextFormatter.ppri=
nt" target=3D"_blank">http://ipython.readthedocs.io/<wbr>en/stable/config/o=
ptions/termi<wbr>nal.html#configtrait-PlainText<wbr>Formatter.pprint</a><br=
><br><br></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote"><d=
iv><div class=3D"gmail-m_-3730345828008721064m_-6421650856597578850h5">On M=
on, Dec 18, 2017 at 7:08 PM, Chris Barker <span dir=3D"ltr">&lt;<a href=3D"=
mailto:[email protected]" target=3D"_blank">[email protected]</a>&g=
t;</span> wrote:<br></div></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef=
t:1ex"><div><div class=3D"gmail-m_-3730345828008721064m_-642165085659757885=
0h5"><div dir=3D"ltr"><div>As Guido has just declared that dicts will now o=
fficially preserve order:<br clear=3D"all"><div><br><a href=3D"https://mail=
.python.org/pipermail/python-dev/2017-December/151283.html" target=3D"_blan=
k">https://mail.python.org/piperm<wbr>ail/python-dev/2017-December/1<wbr>51=
283.html</a><br><br></div><div>I was playing around=C2=A0 them in py3.6 ipy=
thon, and found some (to me) odd behavior:<br><br><span style=3D"font-famil=
y:monospace,monospace">In [1]: d =3D {&#39;one&#39;:1, &#39;two&#39;:2, &#3=
9;three&#39;:3}<br><br>In [2]: d<br>Out[2]: {&#39;one&#39;: 1, &#39;three&#=
39;: 3, &#39;two&#39;: 2}<br><br></span></div>Hmm -- order does not appear =
to be preserved.<br><br></div>But then:<span style=3D"font-family:monospace=
,monospace"></span><br><div><span style=3D"font-family:monospace,monospace"=
></span><div><span style=3D"font-family:monospace,monospace"><br>In [3]: st=
r(d)<br>Out[3]: &quot;{&#39;one&#39;: 1, &#39;two&#39;: 2, &#39;three&#39;:=
 3}&quot;<br><br>In [4]: repr(d)<br>Out[4]: &quot;{&#39;one&#39;: 1, &#39;t=
wo&#39;: 2, &#39;three&#39;: 3}&quot;<br><br>In [5]: d.values()<br>Out[5]: =
dict_values([1, 2, 3])<br><br>In [6]: d.keys()<br>Out[6]: dict_keys([&#39;o=
ne&#39;, &#39;two&#39;, &#39;three&#39;])<br><br>In [7]: d.items()<br>Out[7=
]: dict_items([(&#39;one&#39;, 1), (&#39;two&#39;, 2), (&#39;three&#39;, 3)=
])<br></span><br></div><div>Order IS preserved.<br><br></div><div>So presum=
ably iPython is calling sorted() or some such when displaying a dict. <br><=
br></div><div>Is that that case? Is that documented anywhere?? I can&#39;t =
find it.<br><br></div><div>And with Python &gt;=3D 3.6, dict order is prese=
rved, so it would probably be better to NOT mess with dict order when displ=
aying them in iPython.<br><br></div><div>SIDE NOTE:<br></div><div><br>I had=
 a bit of trouble finding this mailing list -- google still points to the o=
ld ones on <a href=3D"http://scipy.org" target=3D"_blank">scipy.org</a>. --=
 maybe we can put a note on the home page of those lists that they are been=
 moved??<br><br></div><div>(I only noticed, &#39;cause the archives of thos=
e stop last March)<span class=3D"gmail-m_-3730345828008721064m_-64216508565=
97578850m_3404512757170262343HOEnZb"><font color=3D"#888888"><br><br></font=
></span></div><span class=3D"gmail-m_-3730345828008721064m_-642165085659757=
8850m_3404512757170262343HOEnZb"><font color=3D"#888888"><div>-Chris<br></d=
iv><div><br></div><div><br></div><div><br><br></div><div><br>-- <br><div cl=
ass=3D"gmail-m_-3730345828008721064m_-6421650856597578850m_3404512757170262=
343m_-4512783311611731130gmail_signature"><br>Christopher Barker, Ph.D.<br>=
Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&amp;R =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"tel:%28206%29%20526-6959" =
value=3D"+12065266959" target=3D"_blank">(206) 526-6959</a>=C2=A0=C2=A0 voi=
ce<br>7600 Sand Point Way NE =C2=A0=C2=A0<a href=3D"tel:%28206%29%20526-632=
9" value=3D"+12065266329" target=3D"_blank">(206) 526-6329</a>=C2=A0=C2=A0 =
fax<br>Seattle, WA =C2=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0<a href=3D"tel:%28=
206%29%20526-6317" value=3D"+12065266317" target=3D"_blank">(206) 526-6317<=
/a>=C2=A0=C2=A0 main reception<br><br><a href=3D"mailto:[email protected]=
ov" target=3D"_blank">[email protected]</a></div>
</div></font></span></div></div>
<br></div></div>______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">IPython-dev@pyt=
hon.org</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor=
eferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ip=
ython-dev</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">IPython-dev@pyt=
hon.org</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor=
eferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ip=
ython-dev</a><br>
<br></blockquote></div><br><br clear=3D"all"><br>-- <br><div class=3D"gmail=
-m_-3730345828008721064m_-6421650856597578850gmail_signature"><br>Christoph=
er Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOA=
A/NOS/OR&amp;R =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"tel:%282=
06%29%20526-6959" value=3D"+12065266959" target=3D"_blank">(206) 526-6959</=
a>=C2=A0=C2=A0 voice<br>7600 Sand Point Way NE =C2=A0=C2=A0<a href=3D"tel:%=
28206%29%20526-6329" value=3D"+12065266329" target=3D"_blank">(206) 526-632=
9</a>=C2=A0=C2=A0 fax<br>Seattle, WA =C2=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0=
<a href=3D"tel:%28206%29%20526-6317" value=3D"+12065266317" target=3D"_blan=
k">(206) 526-6317</a>=C2=A0=C2=A0 main reception<br><br><a href=3D"mailto:C=
[email protected]" target=3D"_blank">[email protected]</a></div>
</div>
</div></div><br>______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">IPython-dev@pyt=
hon.org</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor=
eferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ip=
ython-dev</a><br>
<br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor=
eferrer" target=3D"_blank">https://mail.python.org/<wbr>mailman/listinfo/ip=
ython-dev</a><br>
<br></blockquote></div><br><br clear=3D"all"><br>-- <br><div class=3D"gmail=
_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency=
 Response Division<br>NOAA/NOS/OR&amp;R =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0(206) 526-6959=C2=A0=C2=A0 voice<br>7600 Sand Point Way NE =C2=A0=C2=
=A0(206) 526-6329=C2=A0=C2=A0 fax<br>Seattle, WA =C2=A098115 =C2=A0 =C2=A0 =
=C2=A0=C2=A0(206) 526-6317=C2=A0=C2=A0 main reception<br><br><a href=3D"mai=
lto:[email protected]" target=3D"_blank">[email protected]</a></div=
>
</div></div>

--94eb2c1f2df4fff56a0560a9c954--

--===============0916086148418846209==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
IPython-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/ipython-dev

--===============0916086148418846209==--