Message Boards Message Boards

0
|
3531 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Dataset and Map Interaction: A Bug?

Posted 10 years ago

I wonder if this is a bug in the interaction between Dataset and Map:

ds = Dataset[{<|"Key" -> "A", "Value" -> 1|>, <|"Key" -> "A", 
     "Value" -> 2|>, <|"Key" -> "B", "Value" -> 10|>, <|"Key" -> "B", 
     "Value" -> 11|>}];
ds[Select[#"Key" == "A" &]]
uniqueKeys = {"A", "B"};
ds[Select[#"Key" == uniqueKeys[[2]] &]] 
ds[Select[#"Key" == # &]] & /@ uniqueKeys

If I run this code, the first ds[Select[ statement returns 2 rows, as I would expect.

The second ds[Select[ statement likewise returns 2 rows.

The final statement, using Map, produces two empty Dataset[] object: 2 levels, but 0 rows in both cases.

Am I doing something wrong? (Wouldn't be the first time....)

POSTED BY: Brad Varey

Dear Brad,

I suppose that that is because the last command actually uses nested pure functions. The "first slot" is different from the "second slot"! For nested slots it is better to use a more explicit definition of pure functions:

Function[in, ds[Select[#"Key" == in & ]]][#] & /@ uniqueKeys

which gives:

enter image description here

I am not sure if this answer actually relates to your question... If not, please ignore.

Cheers,

Marco

POSTED BY: Marco Thiel
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