Skip to content

CSV-encoding header documentation seems to be a bit misleading #15243

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

Closed
on3iro opened this issue Apr 15, 2021 · 9 comments
Closed

CSV-encoding header documentation seems to be a bit misleading #15243

on3iro opened this issue Apr 15, 2021 · 9 comments

Comments

@on3iro
Copy link

on3iro commented Apr 15, 2021

Hey,

I just started using the CSVEncoder and hat some trouble getting it to work with flat data.
The no_headers flag and its description are very misleading in my opinion.

I wanted to create some simple csv like this:

header1;header2;header3
1;a;x
2;b;y
3;c;z

However from the docs it was really hard to figure out how to specify my custom headers, because of the way the conding handles nested data:

$data = [
   [header1, header2, header3]
   [1, a, x],
   [2, b, y],
   [3, c, y]
]

This would not work, because the encoder would automatically set the headers to the surrounding arrays indices [0,1,2].

If I had written this instead:

$data = [
    "header1" => [1,2,3],
    "header2" => [a,b,c],
    ...
]

I would get nested headers instead.

So the solution for this would be to set the no_headers => true flag for the context.
This makes sense if you think about how CSV works, but especially the description "Disables header in the encoded CSV" makes my brain think along the lines "oh, no headers at all" (which of course is nonsense).

I would probably add something along the lines "Disable automatic headers. Use the first data row instead" and maybe add an example, instead.

I can create a PR with an example and suggested documentation if that helps :)

@javiereguiluz
Copy link
Member

javiereguiluz commented Apr 15, 2021

Please, describe the problems that you found and, if possible, the things you'd change or improve. Thanks! (and please, don't use strong language like "irritating", "awful", etc. ... this is voluntary work performed by volunteers, so they deserve to be treated well. Thanks!).

Original comment no longer makes sense because the PR description was updated with examples. Thanks!

@on3iro
Copy link
Author

on3iro commented Apr 15, 2021

sorry accidentally pressed enter

@on3iro
Copy link
Author

on3iro commented Apr 15, 2021

@javiereguiluz I added a few more lines to the issue, sorry for prematurely submitting :)

@on3iro on3iro changed the title CSV-encoding header documentation is irritating CSV-encoding header documentation seems to be a bit misleading Apr 15, 2021
@on3iro
Copy link
Author

on3iro commented Apr 15, 2021

Sorry for using the word "irritating" - it wasn't meant offensive in any way, but I can see how one could interpret it that way :)

@javiereguiluz
Copy link
Member

Theo, thanks a lot for reporting this issue ... and for your quick reaction changing that term. Hopefully this will be reviewed soon and we can improve the reported problem. Cheers!

@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@carsonbot
Copy link
Collaborator

Hello? This issue is about to be closed if nobody replies.

@on3iro
Copy link
Author

on3iro commented Aug 28, 2022

no, I think the point still stands (at least I don't know if anything has happened in that regard since my initial submission)

@javiereguiluz
Copy link
Member

Closing in favor of #17912, a meta-issue that groups all pending serializer-related issues so we can easily check them.

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

4 participants