# Simple dataset query fails

This is really weird.

I can get the first row and a specific column from my Dataset, but when I try to get them both, I receive a cryptic error.

What in the world could it be talking about. myData is the result of a query on a huge proprietary dataset that I really can't upload here. Obviously something simple is broken, but what is it? But more importantly, how do I avoid unexpected breakage like this in the future. Is there a RestoreSanityToDataset[] function?

Oddly, if I add curly braces around the column name, it works fine

Perhaps the FullForm of myData holds a clue. Maybe a Dataset master could look at this and see right off.

    FullForm[Dataset[{Association["Charge" -> 2],
Association["Charge" -> 1]}, TypeSystemAnyType,
Association[
"Origin" ->
HoldComplete[
Query[1 ;; 2, {"Charge"}][
DatasetDatasetHandle[183820416144600]]],
"ID" -> 46304153328976]]]

• What it is talking about is that you have no key "a"; Only the key "Charge". – m_goldberg Jul 7 '17 at 21:06
• Just a typo in my post. I'll fix it shortly. – Chris Nadovich Jul 8 '17 at 0:00
• Interestingly, the same error is returned whether I type "Charge" or I type "Foo" or anything else. It's saying that a string isn't applicable as a part selection. It's not even looking at the actual string. – Chris Nadovich Jul 8 '17 at 0:05
• It is normal here – yode Jul 8 '17 at 5:30
• Yes, @yode, that obviously works. But I have something with the same Normal as what you typed, that came as a result of a query. That simple result that looks entirely the same does not work with that simple query. That's why I included the FullForm. Clearly I'm insane or the type system in Datasets is fubar. – Chris Nadovich Jul 8 '17 at 16:09

This is not really an answer, but an extended comment that includes a work-around.

When I copy the argument of FullForm as InputForm and paste it into a input cell I see

That's a dataset expression of a form I've never seen before and one that the Mathematica's code editor doesn't recognize either. You may be making a simple query, but you are querying something that does not appear to be a simple dataset. I'm not surprised that it behaves strangely.

It occurred to me that it might behave better if it were renormalized.

newds = Dataset[ds // Normal]


Now

newds[1 ;; 2, "Charge"]


gives

as expected.

• Define "simple dataset". I'm querying something that is a list of associations. All associations in the list have exactly the same keys. The value associated with each key has exactly the same structure, typically just one number, but sometimes a list of numbers. I'm really not doing anything fancy -- I thought. It's so frustrating when you invest many days to learn a new topic (Datasets), build something from it, and then encounter erratic behavior nobody understands. – Chris Nadovich Jul 8 '17 at 16:05
• Indeed, renormalizing fixes it. But that's the crux of the question. Is it expected practice to need to renormalize after every query? If so, why isn't that the default format of a query result? Perhaps Dataset[#//Normal] processing should be the default and there should be an option Abnormal to give you the abnormal behavior should you actually want it. – Chris Nadovich Jul 8 '17 at 16:14
• @ChrisNadovich. I did not mean 'simple' as technical term; the usual dictionary definition will do. Or the renormalized form my be considered to define simple in this case. Datasets are a work in progress. They behave a lot better in V11.1.1 than they did in V10.0. I can't say more because the dataset you use in your example was derived by querying another more complicated dataset and you give no information about that process. – m_goldberg Jul 8 '17 at 20:03
• @ChrisNadovich. Unfortunately, I have found renormalization is often necessary, but less so in V11.1.1 than in previous versions. It is something any user of datasets should keep in mind when weirdness happens. – m_goldberg Jul 8 '17 at 20:07
• @ChrisNadovich. Well, that's a nice sentiment and great goal the development team to have :-P Let us pray that we will live to see its achievement. – m_goldberg Jul 13 '17 at 22:32