Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with date columns #62

Closed
peterewills opened this issue Dec 18, 2020 · 2 comments
Closed

Working with date columns #62

peterewills opened this issue Dec 18, 2020 · 2 comments
Labels
question Further information is requested

Comments

@peterewills
Copy link

peterewills commented Dec 18, 2020

FIrst off, thanks for building this - it's making my life a lot easier when I work with data in Observable 馃槃

I'm having some trouble working with dates. I build a data table via

df = aq.from([
  { date: '2020-01-01 00:00:00.000' },
  { date: '2020-01-02 00:00:00.000' }
])

I then add a custom function to shift the date forward 30 days, using moment:

let shiftDateFunc = d => moment(d).add(30, 'days').format()
aq.addFunction("shiftDate", shiftDateFunc)

However, when I try to do

df.derive({shiftedDate: op.shiftDate('date')})

I get an error:

Expression parse error: Invalid date

Which is surprising, since I can map this function over the objects just fine:

df.objects().map(d => shiftDateFunc(d.date)) // succeeds, returns an array of strings

Why can I map this function over the object arrays successfully, but it fails when I register it via addFunction? In my mental model the success of the former should imply that the latter will also work, but obviously I'm confused about something.

@jheer jheer added the question Further information is requested label Dec 18, 2020
@jheer
Copy link
Member

jheer commented Dec 18, 2020

How about this instead? (The op special syntax with string column names is defined only for aggregate and window functions...)

df.derive({shiftedDate: d => op.shiftDate(d.date)})

@peterewills
Copy link
Author

That did it! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants