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

Additional implementation alternative to DictReader #73800

Closed
foxfluff mannequin opened this issue Feb 21, 2017 · 8 comments
Closed

Additional implementation alternative to DictReader #73800

foxfluff mannequin opened this issue Feb 21, 2017 · 8 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@foxfluff
Copy link
Mannequin

foxfluff mannequin commented Feb 21, 2017

BPO 29614
Nosy @rhettinger, @bitdancer, @methane, @serhiy-storchaka, @foxfluff
PRs
  • bpo-29614: Rename and reimplement csv.DictReader. #223
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-02-23.00:06:36.190>
    created_at = <Date 2017-02-21.20:27:20.049>
    labels = ['3.7', 'type-feature', 'library']
    title = 'Additional implementation alternative to DictReader'
    updated_at = <Date 2017-02-23.00:06:36.187>
    user = 'https://github.com/foxfluff'

    bugs.python.org fields:

    activity = <Date 2017-02-23.00:06:36.187>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-02-23.00:06:36.190>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2017-02-21.20:27:20.049>
    creator = 'foxfluff'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29614
    keywords = []
    message_count = 8.0
    messages = ['288318', '288331', '288362', '288365', '288367', '288368', '288369', '288393']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'r.david.murray', 'methane', 'serhiy.storchaka', 'foxfluff']
    pr_nums = ['223']
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue29614'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    @foxfluff
    Copy link
    Mannequin Author

    foxfluff mannequin commented Feb 21, 2017

    As discussed in the following:
    https://bugs.python.org/issue17537
    https://mail.python.org/pipermail/python-ideas/2013-January/018844.html

    DictReader has a feature that will destroy data without warning if fieldnames had duplicate values (manual or automatic entries)

    Proposing renaming and re-implementation of DictReader class to instead return enumerate style output with a child class of DictReader to specifically return a dict object.

    @foxfluff foxfluff mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 21, 2017
    @methane
    Copy link
    Member

    methane commented Feb 22, 2017

    I don't feel TableReader is really useful.

    Would you show some realistic example when TableReader is better than
    normal csv.Reader?

    @bitdancer
    Copy link
    Member

    Inada: I believe the goal is to be able to handle CSV files that have columns with duplicate names. However, in that case one could just use the regular reader class. The only advantage TableReader gives over the regular reader that I can see is that it automatically reads the header line and sets fieldnames. I'm not sure that is enough motivation for introducing a whole new class.

    It also doesn't address the issue the OP mentions, that columns are overwritten silently by DictReader. However, that is a characteristic of dicts in Python in general, so I'm not sure I even see that as a bug.

    Overall, I'm -1 on this proposal.

    @foxfluff
    Copy link
    Mannequin Author

    foxfluff mannequin commented Feb 22, 2017

    David:
    You are correct that the goal is to handle CSVs with duplicate headers, and that the main intention is to have some of the behavior of DictReader without the destruction of data (such as the auto population of field names as you stated).

    It is not the intention of this to change the behavior of DictReader, as stated in bpo-17537. It is instead covering a problem that was discussed later in the thread and would offer an alternative solution with non destructive behavior to DictReader while maintaining backwards compatibility.

    @bitdancer
    Copy link
    Member

    My opinion stated in that issue is still the same: I don't think this is a bug. I don't think automatic handling of fieldnames when no other dictionary features are retained is worth the complication to the API. So I'm still -1. We'll see what other people think.

    @serhiy-storchaka
    Copy link
    Member

    I'm with Inada and David. This use case looks very specific. If you need to handle a CSV file with duplicated header, you can use the regular reader or implement your own specialised reader.

    @serhiy-storchaka
    Copy link
    Member

    Or use DictReader with an explicit fieldnames argument.

    @rhettinger
    Copy link
    Contributor

    I concur with Serhiy, David, and Inada

    Marking this as closed.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants