# Path: rest_pandas/renderers.py
# RESPONSE_ERROR = (
#     "Response data is a %s, not a DataFrame! "
#     "Did you extend PandasMixin?"
# )
# class PandasBaseRenderer(BaseRenderer):
# class PandasFileRenderer(PandasBaseRenderer):
# class PandasHTMLRenderer(TemplateHTMLRenderer, PandasBaseRenderer):
# class PandasCSVRenderer(PandasBaseRenderer):
# class PandasTextRenderer(PandasCSVRenderer):
# class PandasJSONRenderer(PandasBaseRenderer):
# class PandasExcelRenderer(PandasFileRenderer):
# class PandasOldExcelRenderer(PandasFileRenderer):
# class PandasImageRenderer(PandasBaseRenderer):
# class PandasPNGRenderer(PandasImageRenderer):
# class PandasSVGRenderer(PandasImageRenderer):
#     def render(self, data, accepted_media_type=None, renderer_context=None):
#     def render_dataframe(self, data, name, *args, **kwargs):
#     def init_output(self):
#     def get_output(self):
#     def get_pandas_args(self, data):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def init_output(self):
#     def get_pandas_args(self, data):
#     def get_output(self):
#     def render(self, data, accepted_media_type=None, renderer_context=None):
#     def get_template_context(self, data, renderer_context):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def render_dataframe(self, data, name, *args, **kwargs):
#     def init_output(self):
#     def get_pandas_args(self, data):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def get_output(self):


import csv
from .renderers import StringIO


def parse_csv(string):
    """
    Rough port of wq/pandas.js to Python.  Useful for validating CSV output
    generated by Django REST Pandas.
    """
    if not string.startswith(','):
        data = []
        for row in csv.DictReader(StringIO(string)):
            for key, val in row.items():
                try:
                    row[key] = float(val)
                except ValueError:
                    pass
            data.append(row)
        return [{
            'data': data
        }]


# Path: rest_pandas/renderers.py
# RESPONSE_ERROR = (
#     "Response data is a %s, not a DataFrame! "
#     "Did you extend PandasMixin?"
# )
# class PandasBaseRenderer(BaseRenderer):
# class PandasFileRenderer(PandasBaseRenderer):
# class PandasHTMLRenderer(TemplateHTMLRenderer, PandasBaseRenderer):
# class PandasCSVRenderer(PandasBaseRenderer):
# class PandasTextRenderer(PandasCSVRenderer):
# class PandasJSONRenderer(PandasBaseRenderer):
# class PandasExcelRenderer(PandasFileRenderer):
# class PandasOldExcelRenderer(PandasFileRenderer):
# class PandasImageRenderer(PandasBaseRenderer):
# class PandasPNGRenderer(PandasImageRenderer):
# class PandasSVGRenderer(PandasImageRenderer):
#     def render(self, data, accepted_media_type=None, renderer_context=None):
#     def render_dataframe(self, data, name, *args, **kwargs):
#     def init_output(self):
#     def get_output(self):
#     def get_pandas_args(self, data):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def init_output(self):
#     def get_pandas_args(self, data):
#     def get_output(self):
#     def render(self, data, accepted_media_type=None, renderer_context=None):
#     def get_template_context(self, data, renderer_context):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def render_dataframe(self, data, name, *args, **kwargs):
#     def init_output(self):
#     def get_pandas_args(self, data):
#     def get_pandas_kwargs(self, data, renderer_context):
#     def get_output(self):


# Path: rest_pandas/test.py
import csv
from .renderers import StringIO



def parse_csv(string):
    """
    Rough port of wq/pandas.js to Python.  Useful for validating CSV output
    generated by Django REST Pandas.
    """
    if not string.startswith(','):
        data = []
        for row in csv.DictReader(StringIO(string)):
            for key, val in row.items():
                try:
                    row[key] = float(val)
                except ValueError:
                    pass
            data.append(row)
        return [{
            'data': data
        }]


    reader = csv.reader(StringIO(string))