{"record":{"id":"ce69343c3e096ff0","repo":"apache/superset","slug":"error-msg","errorCode":null,"errorMessage":"error_msg","messagePattern":"error_msg","errorType":"exception","errorClass":"DatabaseUploadFailed","httpStatus":422,"severity":"error","filePath":"superset/commands/database/uploaders/csv_reader.py","lineNumber":307,"sourceCode":"                df[column] = df[column].astype(dtype)\n            else:\n                df[column] = df[column].astype(dtype)\n        except (ValueError, TypeError) as ex:\n            try:\n                if dtype in numeric_types:\n                    invalid_mask = CSVReader._find_invalid_values_numeric(df, column)\n                else:\n                    invalid_mask = CSVReader._find_invalid_values_non_numeric(\n                        df, column, dtype\n                    )\n\n                error_msg = CSVReader._create_error_message(\n                    df, column, dtype, invalid_mask, kwargs, ex\n                )\n            except Exception:\n                error_msg = f\"Cannot convert column '{column}' to {dtype}. {str(ex)}\"\n\n            raise DatabaseUploadFailed(message=error_msg) from ex\n\n    @staticmethod\n    def _cast_column_types(\n        df: pd.DataFrame, types: dict[str, str], kwargs: dict[str, Any]\n    ) -> pd.DataFrame:\n        \"\"\"\n        Cast DataFrame columns to specified types with detailed\n        error reporting.\n\n        :param df: DataFrame to cast\n        :param types: Dictionary mapping column names to target types\n        :param kwargs: Original read_csv kwargs for line number calculation\n        :return: DataFrame with casted columns\n        :raises DatabaseUploadFailed: If type conversion fails with detailed error info\n        \"\"\"\n        for column, dtype in types.items():\n            if column not in df.columns:\n                continue","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/uploaders/csv_reader.py#L289-L325","documentation":"DatabaseUploadFailed raised by CSVReader._cast_single_column when converting an uploaded CSV column to the user-specified type fails. The message is built by _create_error_message and lists the offending values with their source line numbers (e.g. \"Cannot convert column 'id' to int64. Found 2 error(s): Line 5: value 'abc'\"); if detail-building itself fails, a fallback message 'Cannot convert column '<c>' to <dtype>. <original error>' is used. It wraps ValueError/TypeError from pd.to_numeric(errors='raise') or DataFrame.astype.","triggerScenarios":"Uploading a CSV and declaring a column type (the types mapping) that the data violates: 'abc' in an int64 column, '1.5' in int64, empty strings in numeric columns, or strings longer than the target dtype permits; line numbers are derived from the original read_csv kwargs (header/skiprows) so they map to the physical CSV rows.","commonSituations":"Excel exports with thousands separators ('1,000') or currency symbols ('$5.00'); European decimal commas ('3,14') parsed as strings; blank cells in NOT NULL integer columns; users picking int64 for columns that legitimately contain floats.","solutions":["Read the detailed message: it names the column, target dtype, and exact lines/values — fix those rows in the CSV or choose the right type","For values like '1,000' or '$5.00', clean them in the source or map the column to string/float64 instead of int64","For mostly-numeric columns with occasional blanks, use float64 (which tolerates NaN) rather than int64","Re-run the upload; the same validation runs again and will confirm the fix"],"exampleFix":"# before: column declared int64 but row 5 contains 'abc'\nid\n1\nabc   <- Line 5\n# after: correct the data\nid\n1\n7\n# or choose dtype float64/string in the column-type picker","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef cast_preview(csv_path: str, types: dict[str, str]) -> list[str]:\n    df = pd.read_csv(csv_path, nrows=1000)\n    bad = []\n    for col, dtype in types.items():\n        try:\n            pd.to_numeric(df[col]) if dtype in {\"int64\", \"float64\", \"int32\", \"float32\"} else df[col].astype(dtype)\n        except (ValueError, TypeError):\n            bad.append(col)\n    return bad  # fix columns in this list before upload","typeGuard":null,"tryCatchPattern":"except DatabaseUploadFailed as ex:\n    # message already lists offending values + line numbers; feed back to user verbatim\n    show_inline_errors(str(ex))","preventionTips":["Preview-cast columns with pandas before choosing types","Prefer float64 over int64 for columns with blanks","Clean thousand separators/currency symbols from numeric exports"],"tags":["csv","pandas","type-cast","data-ingestion"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}