1

I am trying to apply a condition on date hierarchy with the following:

m["additional_refrigerator_equipped2"] = tt.agg.sum(
    tt.where(lvl["date"] > "2019-11-01", 500, 0))

I am getting the below error on visualization:

An error happened during the loading process: "class java.lang.String cannot be cast to class 
java.time.chrono.ChronoLocalDate (java.lang.String and java.time.chrono.ChronoLocalDate
are in module java.base of loader 'bootstrap')"

How can I add the dates to a comparison?

I also checked for NA values but the dates column does not contain any NA values.

1 Answers1

1

Disclaimer: I am a developer at atoti


You need to use a Python date object in the where condition instead of the string:

import datetime as dt

m["additional_refrigerator_equipped2"] = tt.agg.sum(
    tt.where(lvl["date"] > dt.date(2019,11,1), 500, 0)
)

In a simple example with 4 dates it gives a result like this:

cube.query(m["additional_refrigerator_equipped2"], levels=[lvl["date"]])
+------------+-----------------------------------+
| date       | additional_refrigerator_equipped2 |
+------------+-----------------------------------+
| 2019-10-31 | 0                                 |
+------------+-----------------------------------+
| 2019-11-01 | 0                                 |
+------------+-----------------------------------+
| 2019-11-02 | 500                               |
+------------+-----------------------------------+
| 2019-11-03 | 500                               |
+------------+-----------------------------------+
Fabich
  • 2,768
  • 3
  • 30
  • 44
  • There is now an example about this in the [atoti where documentation](https://docs.atoti.io/latest/lib/atoti.html#atoti.where) – Fabich Jan 14 '21 at 11:16