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

bpo-34003: Use dict instead of OrderedDict in csv.DictReader #8014

Merged
merged 5 commits into from Jan 31, 2019

Conversation

Projects
None yet
7 participants
@selik
Copy link
Contributor

commented Jun 29, 2018

DictReader can now use basic dicts instead of OrderedDict, as of version
3.7's change to specify that dict maintains keys in insertion order.
This will be more efficient and more pleasant to read at the interactive
prompt.

I also changed a list comprehension to a generator expression inside of
a ", ".join() to avoid the unnecessary list construction.

https://bugs.python.org/issue34003

Use dict instead of OrderedDict
DictReader can now use basic dicts instead of OrderedDict, as of version
3.7's change to specify that dict maintains keys in insertion order.
This will be more efficient and more pleasant to read at the interactive
prompt.

I also changed a list comprehension to a generator expression inside of
a ``", ".join()`` to avoid the unnecessary list construction.

selik added some commits Jun 29, 2018

@methane

This comment has been minimized.

Copy link
Member

commented Jun 30, 2018

I also changed a list comprehension to a generator expression inside of
a ", ".join() to avoid the unnecessary list construction.

FYI, str.join() creates temporary list if input is not list or tuple. You can't avoid list construction.
Changing list comprehension to genexp make it little slower, because of generator overhead.

$ python3 -m timeit '",".join(str(x) for x in range(10))'
100000 loops, best of 5: 3.46 usec per loop

$ python3 -m timeit '",".join([str(x) for x in range(10)])'
100000 loops, best of 5: 3.09 usec per loop
@selik

This comment has been minimized.

Copy link
Contributor Author

commented Jun 30, 2018

Doh. I should have checked the timings before I assumed. I'll revert that.

revert to list comprehension
str.join creates a list internally if the input is not a list or tuple.
Passing a generator expression only adds overhead.
@BoboTiG
Copy link
Contributor

left a comment

Thanks for the patch :)

@rhettinger rhettinger merged commit 9f3f093 into python:master Jan 31, 2019

9 checks passed

VSTS: Linux-PR Linux-PR_20180630.19 succeeded
Details
VSTS: Linux-PR-Coverage Linux-PR-Coverage_20180630.23 succeeded
Details
VSTS: Windows-PR Windows-PR_20180630.19 succeeded
Details
VSTS: docs docs_20180630.31 succeeded
Details
VSTS: macOS-PR macOS-PR_20180630.19 succeeded
Details
bedevere/issue-number Issue number 34003 found
Details
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@selik selik deleted the selik:fix-issue-34003 branch Jan 31, 2019

.. versionchanged:: 3.6
Returned rows are now of type :class:`OrderedDict`.
.. versionchanged:: 3.8
Returned rows are now of type :class:`dict`.

This comment has been minimized.

Copy link
@merwok

merwok Jan 31, 2019

Contributor

This entry should have been added without deleting the previous one

arnolddumas added a commit to arnolddumas/cpython that referenced this pull request May 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.