TypeError on Values that are Strings
See original GitHub issueDescribe the bug
When attempting to get the .mean()
of a MetricSnapshotDataFrame column that has more that one row, one is presented with a TypeError:
TypeError: Could not convert 26.8206896551724326.82068965517243 to numeric
To Reproduce
Here is what I’ve done to reproduce this error:
from prometheus_api_client import MetricSnapshotDataFrame
faked_data = [
{
'metric': {
'fake': 'data',
},
'value': [1627485628.789, '26.82068965517243']
},
{
'metric': {
'fake': 'data',
},
'value': [1627485628.789, '26.82068965517243']
}
]
df = MetricSnapshotDataFrame(faked_data)
df['value'].mean()
The faked data above is a stripped down version of a response we get directly from Prometheus (Thanos in this instance) using get_current_metric_value
.
Expected behavior
I’d expect that we not see the exception and just get the appropriate data.
Screenshots
Please see the provided reproduction steps.
Additional context
It seems that Pandas deep down is adding the values together, which if they are strings, turns them into massive string values as opposed to distinct numeric values summed together.
I don’t mind working on a PR myself, more wanted to get this out while it was fresh on my mind and I could easily re-produce it 😃
I’m also ok if the expectation is that we (the end users of the package) are expected to clean our data before hand. However, if that is the case, might be good to add a note to the project that this is expected or (as I would provide in a PR) add the mechanism to this package itself and throw a more tailored Exception when we fail to cast the value to an int/float internally to this package.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (10 by maintainers)
Top GitHub Comments
@chauhankaranraj Here we go 😃
#237
@chauhankaranraj I’d love to see if I can give it a go via PR. I’ll take a look this week.