question-mark

Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError on Values that are Strings

See original GitHub issue

Issue Description

Describe 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Shackelford-Ardencommented, Jan 24, 2022

@chauhankaranraj Here we go 😃

#237

1reaction
Shackelford-Ardencommented, Jan 24, 2022

@chauhankaranraj I’d love to see if I can give it a go via PR. I’ll take a look this week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - TypeError: option values must be strings when setting ...
I found out after a while that load_env() must be supplied with a full .env path in order to properly load the environment...
Read more >
TypeError String Indices Must be Integers Python Error [Solved]
How to Access Values from a List in Python. If you encounter this error message, double check to make sure you are using...
Read more >
TypeError: can only concatenate str (not "int") to str
Cause 2: Printing Dictionary Values ... This error can also be triggered by appending values from a collection-type object to a string. Lists,...
Read more >
TypeError: toLowerCase is not a function in JavaScript
To solve the error, make sure to only call the toLowerCase() method on strings. You can convert most values to a string by...
Read more >
TypeError: includes is not a function in JavaScript - Linux Hint
The “includes is not a function” type error occurs when the includes() method is accessed on a value that is neither of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found