Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ruleX from Selection does not work with timestamps (but does with numerics, and with a Param) #502

Closed
frtennis1 opened this issue Aug 25, 2024 · 1 comment · Fixed by #503

Comments

@frtennis1
Copy link
Contributor

The following snippet does not display a vertical rule on mouseover when you set the "x": "ts" (a timestamp) but does when you set "x": "x_val" (a numeric),

x = np.linspace(0,10, num=50)
df = pd.DataFrame({
    "x_val": x, 
    "y_val": np.sin(x), 
    'ts': pd.date_range('2023-05-25 09:30', freq='1min', periods=50)
})

spec = {
    "plot": [
        {
            "mark": "lineY",
            "data": {"from": "df"},
            "x": "ts",
            "y": "y_val",
            'marker': True,
        },
        {"select": "nearestX", "as": "$myXValue"},
        {"mark": "ruleX", "x": "$myXValue"},
    ],
}
MosaicWidget(spec, data={'df': df})

Doesn't work
image

** Does work**

image

Extra curious is that it starts working again for a timestamp if you make $myXValue a regular parameter (instead of a Selection), snippet that works:

spec = {
    "plot": [
        {
            "mark": "lineY",
            "data": {"from": "df"},
            "x": "ts",
            "y": "y_val",
            'marker': True,
        },
        {"select": "nearestX", "as": "$myXValue"},
        {"mark": "ruleX", "x": "$myXValue"},
    ],
    'params': {'myXValue': {'date': '2023-05-25 09:30'}},
}
MosaicWidget(spec, data={'df': df})
image
@jheer
Copy link
Member

jheer commented Aug 26, 2024

Thanks for catching this. In general, selections may not work as they may involve more complicated criteria with multiple values. However, in this case, there is only a single value and so it should be able to work. I updated the clause generation logic of the nearest interactor to recognize this single-field case and generate a compatible selection clause in response, fixing your example.

It is a bit funny that the numeric case still worked... Mosaic was (incorrectly) passing a nested array value to Plot in either case, and Plot apparently extracts the nested numerical value, but not the Date value.

@jheer jheer mentioned this issue Sep 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants