# Buggy code
def _fetch_csv_result(
    query_metadata: _QueryMetadata,
    keep_files: bool,
    chunksize: Optional[int],
    use_threads: bool,
    boto3_session: boto3.Session,
) -> Union[pd.DataFrame, Iterator[pd.DataFrame]]:
    _chunksize: Optional[int] = chunksize if isinstance(chunksize, int) else None
    _logger.debug("_chunksize: %s", _chunksize)
    if (
        query_metadata.output_location is None
        or query_metadata.output_location.endswith(".csv") is False
    ):
        chunked = _chunksize is not None
        return _empty_dataframe_response(chunked, query_metadata)
    path: str = query_metadata.output_location
    s3.wait_objects_exist(paths=[path], use_threads=False, boto3_session=boto3_session)
    _logger.debug("Start CSV reading from %s", path)
    ret = s3.read_csv(
        path=[path],
        dtype=query_metadata.dtype,
        parse_dates=query_metadata.parse_timestamps,
        converters=query_metadata.converters,
        quoting=csv.QUOTE_ALL,
        keep_default_na=False,
        na_values=[""],
        chunksize=_chunksize,
        skip_blank_lines=False,
        use_threads=False,
        boto3_session=boto3_session,
    )
    _logger.debug("Start type casting...")
    _logger.debug(type(ret))
    if _chunksize is None:
        df = _fix_csv_types(
            df=ret,
            parse_dates=query_metadata.parse_dates,
            binaries=query_metadata.binaries,
        )
        df = _apply_query_metadata(df=df, query_metadata=query_metadata)
        if keep_files is False:
            s3.delete_objects(
                path=[path, f"{path}.metadata"],
                use_threads=use_threads,
                boto3_session=boto3_session,
            )
        return df
    dfs = _fix_csv_types_generator(
        dfs=ret,
        parse_dates=query_metadata.parse_dates,
        binaries=query_metadata.binaries,
    )
    dfs = _add_query_metadata_generator(dfs=dfs, query_metadata=query_metadata)
    if keep_files is False:
        return _delete_after_iterate(
            dfs=dfs,
            paths=[path, f"{path}.metadata"],
            use_threads=use_threads,
            boto3_session=boto3_session,
        )
    return dfs


# Traceback (ValueError)
TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "runner.py", line 35, in <module>
}, {})
File "/Users/quarentine/dev/upside/ami-reports/report-generators/athena-report-generator/src/aws.py", line 19, in lambda_handler
reportGenerator.generate_report(request)
File "/Users/quarentine/.virtualenvs/ami-report-generators/lib/python3.7/site-packages/aws_embedded_metrics/metric_scope/__init__.py", line 46, in wrapper
raise e
File "/Users/quarentine/.virtualenvs/ami-report-generators/lib/python3.7/site-packages/aws_embedded_metrics/metric_scope/__init__.py", line 44, in wrapper
return fn(*args, **kwargs)
File "/Users/quarentine/dev/upside/ami-reports/report-generators/athena-report-generator/src/app.py", line 84, in generate_report
df = wr.athena.read_sql_query(query, database=self._database_name, ctas_approach=False)
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/_config.py", line 263, in wrapper
return function(**args)
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/athena/_read.py", line 700, in read_sql_query
boto3_session=session,
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/athena/_read.py", line 504, in _resolve_query_without_cache
boto3_session=boto3_session,
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/athena/_read.py", line 441, in _resolve_query_without_cache_regular
boto3_session=boto3_session,
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/athena/_read.py", line 273, in _fetch_csv_result
boto3_session=boto3_session,
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/s3/_read_text.py", line 265, in read_csv
**pandas_kwargs,
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/s3/_read_text.py", line 128, in _read_text
ret = _read_text_file(path=paths[0], **args)
File "/Users/quarentine/dev/upside/ami-reports/report-generators/aws-data-wrangler/awswrangler/s3/_read_text.py", line 77, in _read_text_file
df: pd.DataFrame = parser_func(f, **pandas_kwargs)
File "/Users/quarentine/.virtualenvs/ami-report-generators/lib/python3.7/site-packages/pandas/io/parsers.py", line 676, in parser_f
return _read(filepath_or_buffer, kwds)
File "/Users/quarentine/.virtualenvs/ami-report-generators/lib/python3.7/site-packages/pandas/io/parsers.py", line 454, in _read
data = parser.read(nrows)
File "/Users/quarentine/.virtualenvs/ami-report-generators/lib/python3.7/site-packages/pandas/io/parsers.py", line 1133, in read
ret = self._engine.read(nrows)
File "/Users/quarentine/.virtualenvs/ami-report-generators/lib/python3.7/site-packages/pandas/io/parsers.py", line 2037, in read
data = self._reader.read(nrows)
File "pandas/_libs/parsers.pyx", line 860, in pandas._libs.parsers.TextReader.read
File "pandas/_libs/parsers.pyx", line 875, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas/_libs/parsers.pyx", line 952, in pandas._libs.parsers.TextReader._read_rows
File "pandas/_libs/parsers.pyx", line 1084, in pandas._libs.parsers.TextReader._convert_column_data
File "pandas/_libs/parsers.pyx", line 1160, in pandas._libs.parsers.TextReader._convert_tokens
ValueError: cannot safely convert passed user dtype of float64 for object dtyped data in column 2

# Fixed code
def _fetch_csv_result(
    query_metadata: _QueryMetadata,
    keep_files: bool,
    chunksize: Optional[int],
    use_threads: bool,
    boto3_session: boto3.Session,
) -> Union[pd.DataFrame, Iterator[pd.DataFrame]]:
    _chunksize: Optional[int] = chunksize if isinstance(chunksize, int) else None
    _logger.debug("_chunksize: %s", _chunksize)
    if (
        query_metadata.output_location is None
        or query_metadata.output_location.endswith(".csv") is False
    ):
        chunked = _chunksize is not None
        return _empty_dataframe_response(chunked, query_metadata)
    path: str = query_metadata.output_location
    s3.wait_objects_exist(paths=[path], use_threads=False, boto3_session=boto3_session)
    _logger.debug("Start CSV reading from %s", path)
    ret = s3.read_csv(
        path=[path],
        dtype=query_metadata.dtype,
        parse_dates=query_metadata.parse_timestamps,
        converters=query_metadata.converters,
        quoting=csv.QUOTE_ALL,
        keep_default_na=False,
        na_values=["", "NaN"],
        chunksize=_chunksize,
        skip_blank_lines=False,
        use_threads=False,
        boto3_session=boto3_session,
    )
    _logger.debug("Start type casting...")
    _logger.debug(type(ret))
    if _chunksize is None:
        df = _fix_csv_types(
            df=ret,
            parse_dates=query_metadata.parse_dates,
            binaries=query_metadata.binaries,
        )
        df = _apply_query_metadata(df=df, query_metadata=query_metadata)
        if keep_files is False:
            s3.delete_objects(
                path=[path, f"{path}.metadata"],
                use_threads=use_threads,
                boto3_session=boto3_session,
            )
        return df
    dfs = _fix_csv_types_generator(
        dfs=ret,
        parse_dates=query_metadata.parse_dates,
        binaries=query_metadata.binaries,
    )
    dfs = _add_query_metadata_generator(dfs=dfs, query_metadata=query_metadata)
    if keep_files is False:
        return _delete_after_iterate(
            dfs=dfs,
            paths=[path, f"{path}.metadata"],
            use_threads=use_threads,
            boto3_session=boto3_session,
        )
    return dfs