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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge fails with TypeError #239

Open
ThomDietrich opened this issue Dec 2, 2020 · 2 comments
Open

Merge fails with TypeError #239

ThomDietrich opened this issue Dec 2, 2020 · 2 comments

Comments

@ThomDietrich
Copy link

ThomDietrich commented Dec 2, 2020

Hey there, I want to report the following bug.
In case I am not correct and this is wrong use on my end, I wonder if documentation needs to be updated.
All the best!


Python 3.8.5, traces 0.6.0

import traces
ts = [traces.TimeSeries(), traces.TimeSeries()]
ts[1][2] = 3
traces.TimeSeries.merge(ts, operation=sum)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/traces/timeseries.py", line 778, in merge
    default = operation(default)
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
@tasq-inc
Copy link

tasq-inc commented Apr 9, 2021

I found a work around for now. It would seem that NoneType is produced probably when data is not present for the time interval being merged and aggregated. Passing in a custom aggregate function that forces NoneType to 0 worked for me:

import traces

def custom_func(x):
    x_fillna = [i if i else 0 for i in x]
    return sum(x_fillna)

ts = [traces.TimeSeries(), traces.TimeSeries()]
ts[1][2] = 3
traces.TimeSeries.merge(ts, operation=custom_func)

@stringertheory
Copy link
Owner

@ThomDietrich thanks for opening this issue! It's a great idea to improve the documentation about this.

(The Exception is the desired behavior in this case. The first time series has the default value None for all times, and the second is None for all times before 2, and then 3 afterwards. At, for example, t=4, merge with operation=sum is summing None + 3, and does not automatically assume that Nones should be ignored).

Thanks @tasq-inc for posting a solution. This solution or something similar is exactly what I'd suggest using if you want to ignore Nones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants