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

Unexpected results when instantiating a dataset from array of 2-element arrays where first element is a string or keyword #142

Closed
kiramclean opened this issue Mar 20, 2024 · 2 comments · Fixed by #143
Assignees
Labels
bug Something isn't working

Comments

@kiramclean
Copy link
Member

One would expect the following to create a dataset with 2 columns and rows populated with the data from each tuple, but you get an unexpected result (a 3x2 dataset)

(tc/dataset [["a" 2] ["b" 3] ["c" 4]] {:column-names ["Col A" "Col B"]})
;; >>>
| a | b | c |
|--:|--:|--:|
| 2 | 3 | 4 |

(as opposed to)

| Col A | Col B |
|------:|------:|
|     a |     2 |
|     b |     3 |
|     c |     4 |

The offending lines of code are here:
https://github.com/scicloj/tablecloth/blob/master/src/tablecloth/api/dataset.clj#L75-L79

One possible solution is to just remove this special handling of 2-element iterables and issue a breaking release, another might be to handle the case where a map is given (which seems to be what this is trying to catch, I think?), but not apply the same logic to all 2-element seqs (which would still be a breaking change).

I'd be happy to contribute a PR once a decision is made about if/how to address this issue.

@genmeblog
Copy link
Member

Yes... As we've discussed on Zulip, solution proposed by jsa is probably the best here.

If :column-names are defined - treat seq of pairs as rows, otherwise treat as it is now.

What do you think?

@genmeblog
Copy link
Member

@kiramclean kiramclean self-assigned this Mar 20, 2024
@kiramclean kiramclean added the bug Something isn't working label Mar 20, 2024
@kiramclean kiramclean changed the title Unexpected results when instantiating a dataset from a array of 2-element arrays where one element is a string or keyword Unexpected results when instantiating a dataset from array of 2-element arrays where one element is a string or keyword Mar 21, 2024
@kiramclean kiramclean changed the title Unexpected results when instantiating a dataset from array of 2-element arrays where one element is a string or keyword Unexpected results when instantiating a dataset from array of 2-element arrays where first element is a string or keyword Mar 21, 2024
eraderna added a commit to MastodonC/witan.sen2 that referenced this issue May 27, 2024
Following [removal of inconsistent method for forming datasets from
arrays of 2-element arrays where first element is a string or
keyword](scicloj/tablecloth#142) in TC v7.029.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants