Message Boards Message Boards

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

Tabular feature quirk in version 14.2

Posted 1 day 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
4 Replies

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

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
Posted 20 hours 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 19 hours 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
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