Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 pandas json encoding problem #416

Closed
LilithWittmann opened this issue Sep 17, 2015 · 7 comments
Closed

Python3 pandas json encoding problem #416

LilithWittmann opened this issue Sep 17, 2015 · 7 comments

Comments

@LilithWittmann
Copy link
Contributor

I tried to use the charts function of airflow but every query I run returns an internal server error. I think it has something to do with json encoding of the pandas object.
My system:

  • centos 7
  • python 3.4
  • airflow 1.5.1
  • postgresql 9.4
Traceback (most recent call last):
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask_admin/base.py", line 68, in inner
    return self._run_view(f, *args, **kwargs)
  File "/var/www/airflow/env/lib/python3.4/site-packages/flask_admin/base.py", line 359, in _run_view
    return fn(self, *args, **kwargs)
  File "/var/www/airflow/env/lib/python3.4/site-packages/airflow/www/app.py", line 112, in decorated_function
    return f(*args, **kwargs)
  File "/var/www/airflow/env/lib/python3.4/site-packages/airflow/www/utils.py", line 96, in view_func
    return f(*args, **kwargs)
  File "/var/www/airflow/env/lib/python3.4/site-packages/airflow/www/app.py", line 607, in chart_data
    response=json.dumps(payload, indent=4, default=date_handler),
  File "/usr/lib64/python3.4/json/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/usr/lib64/python3.4/json/encoder.py", line 194, in encode
    chunks = list(chunks)
  File "/usr/lib64/python3.4/json/encoder.py", line 422, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib64/python3.4/json/encoder.py", line 396, in _iterencode_dict
    yield from chunks
  File "/usr/lib64/python3.4/json/encoder.py", line 396, in _iterencode_dict
    yield from chunks
  File "/usr/lib64/python3.4/json/encoder.py", line 317, in _iterencode_list
    yield from chunks
  File "/usr/lib64/python3.4/json/encoder.py", line 430, in _iterencode
    yield from _iterencode(o, _current_indent_level)
  File "/usr/lib64/python3.4/json/encoder.py", line 427, in _iterencode
    raise ValueError("Circular reference detected")
ValueError: Circular reference detected

This is the object that can't be encoded:

{'columns': [{'title': 'year'}, {'title': 'price'}], 'data': [[2000.0, 9900.2], [2010.0, 76666.2], [2011.0, 3432.3], [2012.0, 5444.2], [2013.0, 2345.332], [2014.0, 34444.33], [2015.0, 414.4027888224663]], 'index': [0, 1, 2, 3, 4, 5, 6]}
@mistercrunch
Copy link
Member

Weird, how can json have a circular reference? it makes no sense to me... But with a bit of googling it looks like it's coming from the date_handler function:

http://stackoverflow.com/questions/14249115/serializing-output-to-json-valueerror-circular-reference-detected

@mistercrunch
Copy link
Member

This may help:
#420

@LilithWittmann
Copy link
Contributor Author

Ok after I found some other issues related to python3 I switched back to python2 /o\ (but there it works…)

@jlowin
Copy link
Member

jlowin commented Sep 18, 2015

@LilithWittmann could you please create issues for any Py3 problems you encounter? We'll try to squash them.

@LilithWittmann
Copy link
Contributor Author

@jlowin Ok ( e.g. #422, #414 )

@jlowin
Copy link
Member

jlowin commented Sep 18, 2015

Thanks! Unfortunately mysql has been problematic for Py3 in the past but I don't use it here so I have trouble testing for compatibility. Let's see if anyone can help.

@jlowin
Copy link
Member

jlowin commented Mar 28, 2016

Believe this was closed with #427, please reopen if not.

@jlowin jlowin closed this as completed Mar 28, 2016
mobuchowski added a commit to mobuchowski/airflow that referenced this issue Jan 4, 2022
* spark: visitors for commands

Signed-off-by: Maciej Obuchowski <[email protected]>

* spark: emit on sql events (apache#404)

Signed-off-by: Maciej Obuchowski <[email protected]>

* OptimizedCreateHiveTableAsSelectCommandVisitor with tests (apache#414)

Signed-off-by: Pawel Leszczynski <[email protected]>

* AlterTableCommands visitors (apache#415)

Signed-off-by: Pawel Leszczynski <[email protected]>

* spark: implement PathUtils (apache#416)

Signed-off-by: Maciej Obuchowski <[email protected]>

* spark: move existing visitor implementations to PathUtils (apache#417)

Signed-off-by: Maciej Obuchowski <[email protected]>

* spark: split CreateTableLikeCommandVisitor implementation due to api change (apache#418)

Signed-off-by: Maciej Obuchowski <[email protected]>

* [INTEGRATION][Spark] implement DataFrameWriterV2's CreateTableAsSelect (apache#419)

* spark: split CreateTableLikeCommandVisitor implementation due to api change

Signed-off-by: Maciej Obuchowski <[email protected]>

* spark: implement DataFrameWriterV2's CreateTableAsSelect for Iceberg and Delta

Signed-off-by: Maciej Obuchowski <[email protected]>

* merge fromHiveTable & fromCatalogTable methods (apache#432)

Signed-off-by: Pawel Leszczynski <[email protected]>

* create & drop table with tests (apache#424)

Signed-off-by: Pawel Leszczynski <[email protected]>

Co-authored-by: pawel.leszczynski <[email protected]>
Co-authored-by: Michael Collado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants