0

I am trying to check if a floating column is actually an int column before converting it to string column, (exact use case: 123.00 needs to be 123, '123-4' needs to remain '123-4').

Code:

    # series: modin pandas Series
    try:
        # If it's a int (123.0)
        return series.astype(int).astype(str)
    except Exception:
        # If it's a string (12-3)
        return series.astype(str)

However, the exception is not caught

ValueError: invalid literal for int() with base 10: '123-4'

ray.exceptions.RayTaskError(ValueError): ray::apply_func()

I have tried with except:, except ValueError:,

from ray.exceptions import RayTaskError
except RayTaskError:

Update: Present as a github issue: https://github.com/modin-project/modin/issues/3966

Susmit
  • 336
  • 1
  • 4
  • 12
  • You mention "exact use case: 123.00 needs to be 123", but the exception says "ValueError: invalid literal for int() with base 10: '123-4'". What type of object (e.g. str, float) does the input series have, and what kinds of values do you expect (e.g. "123-4", "123.00", "123.15")? What would you like to do with each kind of value (e.g. raise an exception for "123-4", convert "123.12" to 123, and convert "123.00" to 123")? – rdurrani Dec 16 '21 at 19:03
  • @rdurrani Updated my question, if it is a string which cannot be converted to a int, it has to remain as a string. The issue is that python is not able to catch RayTaskError – Susmit Dec 17 '21 at 06:12
  • Hi @Susmit! I think one possible solution to your problem could be to try doing `pd.Series(...).str.isnumeric().all()` which will return `True` if every value in the Series is numeric, and `False` if not. For context, when using ray as a backend it catches and serializes any exceptions to raise them as RayTaskErrors, which is why the code doesn't work as expected! – rdurrani Jan 11 '22 at 19:59
  • Hi @rdurrani Currently I have created a separate class for everything which doesn't work in Modin, basically I convert Modin series to pandas series and then convert it back. It would really be great if Modin provided a wrapper around catching ray task error – Susmit Jan 12 '22 at 10:45
  • Hi @Susmit! That makes a lot of sense - thank you for bringing this up! I've gone ahead and opened an [issue](https://github.com/modin-project/modin/issues/3966) on our [repo](https://github.com/modin-project/modin)! I'd really appreciate if you could leave a comment describing your use case in a bit more detail for more context! – rdurrani Jan 13 '22 at 20:16
  • Hi @rdurrani, added my comments in the github issue. – Susmit Jan 14 '22 at 13:26

0 Answers0