3
$\begingroup$

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.

enter image description here

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

enter image description here

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]}, TypeSystem`AnyType, 
     Association[
   "Origin" -> 
    HoldComplete[
     Query[1 ;; 2, {"Charge"}][
      Dataset`DatasetHandle[183820416144600]]], 
       "ID" -> 46304153328976]]]
$\endgroup$
  • 1
    $\begingroup$ What it is talking about is that you have no key "a"; Only the key "Charge". $\endgroup$ – m_goldberg Jul 7 '17 at 21:06
  • $\begingroup$ Just a typo in my post. I'll fix it shortly. $\endgroup$ – Chris Nadovich Jul 8 '17 at 0:00
  • $\begingroup$ 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. $\endgroup$ – Chris Nadovich Jul 8 '17 at 0:05
  • $\begingroup$ It is normal here $\endgroup$ – yode Jul 8 '17 at 5:30
  • $\begingroup$ 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. $\endgroup$ – Chris Nadovich Jul 8 '17 at 16:09
2
$\begingroup$

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

dataset

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]

newds

Now

newds[1 ;; 2, "Charge"]

gives

result

as expected.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Chris Nadovich Jul 8 '17 at 16:05
  • $\begingroup$ 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. $\endgroup$ – Chris Nadovich Jul 8 '17 at 16:14
  • $\begingroup$ @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. $\endgroup$ – m_goldberg Jul 8 '17 at 20:03
  • 1
    $\begingroup$ @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. $\endgroup$ – m_goldberg Jul 8 '17 at 20:07
  • 1
    $\begingroup$ @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. $\endgroup$ – m_goldberg Jul 13 '17 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.