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.

Failing to specify numeric columns fails with "could not convert foofoo to numeric"

See original GitHub issue

A minor suggestion to improve error messages: The following code fails, because the meta data does not specify that column A is numeric. However, the error message is somewhat non-intuitive:

import pandas as pd
import dask.dataframe as dd
from dask import delayed

df = pd.DataFrame({"A": [1, 2, 3]})
ddf = dd.from_delayed(delayed(lambda: df), meta=pd.DataFrame(columns=["A"]))
ddf["A"].mean()
# TypeError: Could not convert foofoo to numeric

This is probably a consequence of the data in _simple_fake_mapping in dataframe/utils.py. It would be good to turn the error into something more explicit mentioning the column name + dtype, so that users don’t start to search for foofoo.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jcristcommented, Jun 14, 2017

explicit hint that the meta data must be wrong.

If the column is actually an object column, then the metadata doesn’t have to be wrong, the operation is just invalid. I’d rather fix series reductions to check for object dtype, and error explicitly with ValueError("mean reduction not supported for object dtype"). If the metadata was correct, this is a better error message than what pandas throws. If the metadata is wrong, the user will see “object dtype” and should be able to track down their prior mistake.

0reactions
bluenote10commented, Jun 14, 2017

My idea would be to wrap all lines like this into:

with safe_meta_numerics():
    meta = self._meta_nonempty.mean(axis=axis, skipna=skipna)

with an appropriate context manager that catches only TypeError containing “Could not convert” and re-raises with an explicit hint that the meta data must be wrong.

It took me quite some time to make sense of this error, probably because:

  • I did explicitly specify meta including dtypes, just with a tiny mistake.
  • From a user perspective the .mean() is a lazy operation, so it was surprising to see hints of a numeric operation in the first place.
  • The “foofoo” pointed me in the wrong direction, checking my code & data for “foofoo”.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is R tune_grid() having an issue with non-numeric ...
Some columns are non-numeric. The data cannot be converted to numeric matrix: 'Company', # 'State', 'Zip'." Note, the product_folds include ...
Read more >
Error with Data Type: We could not convert to number
Hi, I have a column (100 million rows) with Data Type: Decimal Number which generates an error because a number is written 8,005,5...
Read more >
Convert numbers stored as text to numbers
Numbers that are stored as text can cause unexpected results. Select the cells, and then click Excel Error Alert button to choose a...
Read more >
File: NEWS — Documentation by YARD 0.9.20 - Shoulda Matchers
Fix validate_inclusion_of so that if it fails, it will no longer blow up with ... no longer raises an IneffectiveTestError if used against...
Read more >
invalid parameter number: - You.com | The search engine ...
"Invalid parameter number: parameter was not defined" Inserting data ... then the insert will fail, because there is only 1 column name referenced...
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