Message Boards Message Boards

1
|
480 Views
|
6 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Tabular feature quirk in version 14.2

Posted 8 days ago

The new "Tabular" feature is a welcome addition to the "Dataset" and "Associations" data structures. It looks like there is a little quirk that caught me out. Maybe it's a bug, Or maybe i'm on dope. If the key is assigned to a variable, the query into the tabular data using the variable comes up empty. Whereas the more direct use of the key completes the query successfully.

You can avoid this behavior by wrapping the Tabular data in a Dataset.

POSTED BY: Mark Holmes
6 Replies
Posted 8 days ago

Howdy, Mark From the examples I’ve seen in Wolfram’s post and Documentation, I think your use of “location” as a string was a problem. Try just #location... Select[test, (#location == "familyroom" &)]

Block[{test, select}, 
 test = Tabular[{<|"location" -> "study", 
     "temperaturesensor" -> "SHTC3"|>, <|"location" -> "basement", 
     "temperaturesensor" -> "BME280"|>, <|"location" -> "familyroom", 
     "temperaturesensor" -> "BME280"|>, <|"location" -> "Study", 
     "temperaturesensor" -> Missing["NotAvailable"]|>, <|"location" ->
       "DiningRoom", 
     "temperaturesensor" -> "MCP9808"|>, <|"location" -> "upstairs", 
     "temperaturesensor" -> "MCP9808"|>, <|"location" -> "Thermostat",
      "temperaturesensor" -> "DPS310"|>, <|"location" -> "FamilyTV", 
     "temperaturesensor" -> "TMP117"|>, <|"location" -> 
      "Indeterminate", 
     "temperaturesensor" -> "BME680"|>, <|"location" -> "LaniStudy", 
     "temperaturesensor" -> "BME680"|>, <|"location" -> "Basement", 
     "temperaturesensor" -> "BME680"|>}];
 select = Select[test, (#location == "familyroom" &)];
 Row[{test, Spacer[12], "\[LongRightArrow] ", select}]
 ]
POSTED BY: David Barnes
Posted 8 days ago

Howdy, Mark From the examples I’ve seen in Wolfram’s post and Documentation, I think your use of “location” as a string was a problem. Try just #location... Select[test, (#location == "familyroom" &)]

Block[{test, select}, 
 test = Tabular[{<|"location" -> "study", 
     "temperaturesensor" -> "SHTC3"|>, <|"location" -> "basement", 
     "temperaturesensor" -> "BME280"|>, <|"location" -> "familyroom", 
     "temperaturesensor" -> "BME280"|>, <|"location" -> "Study", 
     "temperaturesensor" -> Missing["NotAvailable"]|>, <|"location" ->
       "DiningRoom", 
     "temperaturesensor" -> "MCP9808"|>, <|"location" -> "upstairs", 
     "temperaturesensor" -> "MCP9808"|>, <|"location" -> "Thermostat",
      "temperaturesensor" -> "DPS310"|>, <|"location" -> "FamilyTV", 
     "temperaturesensor" -> "TMP117"|>, <|"location" -> 
      "Indeterminate", 
     "temperaturesensor" -> "BME680"|>, <|"location" -> "LaniStudy", 
     "temperaturesensor" -> "BME680"|>, <|"location" -> "Basement", 
     "temperaturesensor" -> "BME680"|>}];
 select = Select[test, (#location == "familyroom" &)];
 Row[{test, Spacer[12], "\[LongRightArrow] ", select}]
 ]

Well, What I wrote works, but not if the column name was “temperature_sensor”. Then You would need to define it as a string…

Block[{test, select2}, 
 test = Tabular[{<|"location" -> "study", 
     "temperature_sensor" -> "SHTC3"|>, <|"location" -> "basement", 
     "temperature_sensor" -> "BME280"|>, <|"location" -> "familyroom",
      "temperature_sensor" -> "BME280"|>, <|"location" -> "Study", 
     "temperature_sensor" -> Missing["NotAvailable"]|>, <|"location" ->
       "DiningRoom", 
     "temperature_sensor" -> "MCP9808"|>, <|"location" -> "upstairs", 
     "temperature_sensor" -> "MCP9808"|>, <|"location" -> "Thermostat",
      "temperature_sensor" -> "DPS310"|>, <|"location" -> "FamilyTV", 
     "temperature_sensor" -> "TMP117"|>, <|"location" -> 
      "Indeterminate", 
     "temperature_sensor" -> "BME680"|>, <|"location" -> "LaniStudy", 
     "temperature_sensor" -> "BME680"|>, <|"location" -> "Basement", 
     "temperature_sensor" -> "BME680"|>}];
 select2 = Select[test, (#"temperature_sensor" === "BME280" &)];
 Row[{test, Spacer[12], "\[LongRightArrow] ", select2}]
 ]
POSTED BY: David Barnes

Mark, try localizing the symbol testKey with With:

testKey = "location"; 
Select[test, (#[testKey] == "familyroom" &)] // Normal
(* {} *)

With[{testKey = "location"}, 
   Select[test, (#[testKey] == "familyroom" &)] 
 ] // Normal
(*  {<|"location" -> "familyroom", "temperaturesensor" -> "BME280"|>} *)

I don't know why the global testKey does not work. I seems to me it should.

POSTED BY: Carl Verdon

Thank you for the comments!

This was from a function that performed the extraction with Key Strings passed as an argument. The example code didn't make the context clear. That was why it used a variable instead of the string. It's a pretty narrow case,

Take care, Mark

POSTED BY: Mark Holmes

I'm still unsure how to select a column in a Tabular dataset. I tried the approach we have in Dataset. Let's assume we have dataset= Dataset[data] with column c, I can access the values in c by just writing dataset["c"]. However, doing so with Tabular I get an error.

Dalila,

With Tabular, use the same specification used for Part, e.g., dataset[All, "c"] gives the TabularColumn object for "c". Use Normal to get a list of its values. Substitute All with any other valid Part specification, e.g., 1;;5 to get rows 1 through 5.

POSTED BY: Carl Verdon
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract