question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Applying the extent transform to a field that contains Date instances returns an array of timestamps

See original GitHub issue

Applying the extent transform to a field that contains Date instances returns an array of timestamps rather than an array of Date instances.

To recreate, paste the following specification into the Vega Editor. Notice that the value of the dateDomain signal is an array of timestamps rather than an array of Date instances, even though the date field contains Date instances.

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": [
    {
      "name": "table",
      "transform": [
        {"type": "sequence", "start": 1, "stop": 8, "as": "index"},
        {
          "type": "formula",
          "expr": "datetime(2021, 0, datum.index)",
          "as": "date"
        },
        {"type": "formula", "expr": "time(datum.date)", "as": "timestamp"},
        {"type": "extent", "field": "date", "signal": "dateDomain"}
      ]
    }
  ]
}

I’ve raised this bug because I think that the extent of a field should have the same type as the field: one would expect a field of numbers to have an extent that was also numbers, for example. However, I appreciate that Date instances can be problematic and that returning timestamps may be preferable. If this is a feature rather than a bug, then I will open a PR on the documentation.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jheercommented, Feb 10, 2021

Yes, or just +date suffices for date-to-number coercion in most situations, assuming no null values are involved.

1reaction
domoritzcommented, Feb 10, 2021

You are right, Vega does not transparently handle timestamps/datetime in custom expressions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the elegant way to get the latest date from array of ...
A clean way to do it would be to convert each date to a Date() and take the max. ES6: new Date(Math.max(...a.map(e =>...
Read more >
MATLAB datevec - MathWorks
This MATLAB function converts the datetime or duration value t to a date vector—that is, a numeric vector whose six elements represent the...
Read more >
Array functions | BigQuery - Google Cloud
The ARRAY function returns an ARRAY with one element for each row in a subquery. If subquery produces a SQL table, the table...
Read more >
Time series / date functionality — pandas 1.5.2 documentation
Under the hood, pandas represents timestamps using instances of Timestamp and sequences of ... Returns datetime.date (does not contain timezone information).
Read more >
Convert a Field to a Date Field - Tableau Help
Create a calculation using the DATEPARSE function ... Dates are stored in a nearly infinite array of formats. Some date fields have years...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found