Skip to content

ValueError: invalid error value specified (Pandas 2.0+ Incompatibility) #89

@jarbaas

Description

@jarbaas

Description

Crash encountered when using parse() on a .gct file. The code appears to be incompatible with newer versions of Pandas, where the errors='ignore' argument in pd.to_numeric has been deprecated.

Traceback

File ".../site-packages/cmapPy/pandasGEXpress/parse_gct.py", line 139, in parse
    (row_metadata, col_metadata, data) = parse_into_3_df(
                                         ~~~~~~~~~~~~~~~^
        file_path, num_data_rows, num_data_cols,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        num_row_metadata, num_col_metadata, nan_values)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/cmapPy/pandasGEXpress/parse_gct.py", line 224, in parse_into_3_df
    row_metadata = assemble_row_metadata(full_df, num_col_metadata, num_data_rows, num_row_metadata)
File ".../site-packages/cmapPy/pandasGEXpress/parse_gct.py", line 251, in assemble_row_metadata
    row_metadata = row_metadata.apply(lambda x: pd.to_numeric(x, errors="ignore"))
File ".../site-packages/pandas/core/frame.py", line 12419, in apply
    return op.apply().__finalize__(self, method="apply")
           ~~~~~~~~^^
File ".../site-packages/pandas/core/apply.py", line 1015, in apply
    return self.apply_standard()
           ~~~~~~~~~~~~~~~~~~~^^
File ".../site-packages/pandas/core/apply.py", line 1167, in apply_standard
    results, res_index = self.apply_series_generator()
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File ".../site-packages/pandas/core/apply.py", line 1183, in apply_series_generator
    results[i] = self.func(v, *self.args, **self.kwargs)
                 ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/cmapPy/pandasGEXpress/parse_gct.py", line 251, in <lambda>
    row_metadata = row_metadata.apply(lambda x: pd.to_numeric(x, errors="ignore"))
                                                 ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/pandas/core/tools/numeric.py", line 183, in to_numeric
    raise ValueError("invalid error value specified")
ValueError: invalid error value specified

Fix

The following at line 251 can fix the issue locally:

def safe_convert(x):
    try:
        return pd.to_numeric(x)
    except:
        return x
row_metadata = row_metadata.apply(safe_convert)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions