scicloj / tablecloth.time

Tools for the processing and manipulation of time-series data in Clojure.
Other
18 stars 1 forks source link

Use `validatable` to check :index meta validity #48

Closed ezmiller closed 3 years ago

ezmiller commented 3 years ago

Goal / Problem

In #31 we adjusted index-by to set a simple metadata key :index on the dataset to handle cases where it is not possible to detect the time column automatically (i.e. if there is one time column). But simply setting this metadata can lead to a problem if the index column is changed so that it becomes invalid. We need to check whether the index is invalid.

Proposed Solution

@daslu added a mechanism to check the validity in #5. This PR uses the add-validatable method to add the index metadata whe the user calls index-by. Then it changes the index-column-name fn to check the validity of the validatable index metadata.

(def ds (dataset {:x [1 2 3]
                  :y [4 5 6]}))

(-> ds
    (index-by :x)
    (idx-utils/index-column-name))
;; => :x

(-> ds
    (index-by :x)
    (rename-columns {:x :z})
    (idx-utils/index-column-name))
;; => nil

See the tablecloth.time.utils.indexing-test namespace for a bit more detail.

Also in this PR