vega-lite: Off-by-one error in year-month timeUnit
The following specification has dates starting and ending in the month of June, but the chart renders with data starting and ending in the month of May. Reported in https://github.com/altair-viz/altair/issues/1027
{
"data": {
"values": [
{"date": "2017-06-01", "pct_change_rounded": 0},
{"date": "2017-07-01", "pct_change_rounded": 0.1},
{"date": "2017-08-01", "pct_change_rounded": 0.4},
{"date": "2017-09-01", "pct_change_rounded": 0.5},
{"date": "2017-10-01", "pct_change_rounded": 0.1},
{"date": "2017-11-01", "pct_change_rounded": 0.3},
{"date": "2017-12-01", "pct_change_rounded": 0.2},
{"date": "2018-01-01", "pct_change_rounded": 0.5},
{"date": "2018-02-01", "pct_change_rounded": 0.2},
{"date": "2018-03-01", "pct_change_rounded": -0.1},
{"date": "2018-04-01", "pct_change_rounded": 0.2},
{"date": "2018-05-01", "pct_change_rounded": 0.2},
{"date": "2018-06-01", "pct_change_rounded": 0.1}
]
},
"mark": "bar",
"encoding": {
"x": {
"type": "ordinal",
"axis": {"format": "%b %y"},
"field": "date",
"timeUnit": "yearmonth"
},
"y": {"type": "quantitative", "field": "pct_change_rounded"}
}
}

About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (15 by maintainers)
If you’re using Altair with Pandas dataframes & datetimes, then you haven’t been using ISO and I think the change I have in mind at https://github.com/altair-viz/altair/issues/1027 will fix things for you.
We’re having a discussion about this in the vega slack in #altair.
The short story is that JavaScript date parsing is odd and it’s hard to get around that.