mikedewar / d3py

a plottling library for python, based on D3
1.42k stars 202 forks source link

add a method to Figure that takes in new data #14

Open mikedewar opened 12 years ago

mikedewar commented 12 years ago

The new method should look like

data = DataFrame({'y' = [1,2,3], 'x' = [1,2,3]})
p = Figure(data)
p += Line(x='x', y='y')
p += DataFrame({'z' = [3,4,5], 'x' = [2,3,4]})
p += Line(x='x', y='z')

and the internal data frame should have merged the xs and added missing data for the ys and zs that don't have data points.

mikedewar commented 12 years ago

Panda's combine does the trick nicely:

combiner = lambda x, y: np.where(isnull(x), y, x)
df1.combine(df2, combiner)
mynameisfiber commented 12 years ago

That's great! One thing though: do we want all this functionality by massively overloading the addition operator?

One consequence of this would be many isinstance checks in __add__ which I find incredibly ugly! Maybe we can have reasonable helper functions that do this data combination for you. The main thing I don't like about overloading add this way is that you never know what the result of the operation is: it does drastically different things based on the incoming type. (this is one of the things I hate most about my implementation of the javascript module).

So, any thoughts?