Skip to content

Pandas categories support not implemented #453

@caspark

Description

@caspark

Summary

Streamlit seems to be unable to render Pandas series or dataframes which contain categorical elements, throwing a NotImplementedError: Dtype category not understood. error.

Steps to reproduce

  1. Create a streamlit file with contents of
import streamlit as st
import pandas as pd

s = pd.Series(["a","b","c","a"], dtype="category")
st.write(s)
  1. Run the file with streamlit and view the served result in the browser

Expected behavior:

s is rendered as a table or datatable.

Actual behavior:

An error along the lines of

NotImplementedError: Dtype category not understood.
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/__init__.py", line 352, in write dataframe(arg) # noqa: F821
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/__init__.py", line 126, in wrapped_method return method(dg, *args, **kwargs)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 79, in wrapped_method return method(self, *args, **kwargs)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 789, in dataframe set_data_frame, "dataframe", elementWidth=width, elementHeight=height
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 317, in _enqueue_new_element_delta rv = marshall_element(msg.delta.new_element)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 786, in set_data_frame data_frame_proto.marshall_data_frame(data, delta.data_frame)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/elements/data_frame_proto.py", line 50, in marshall_data_frame _marshall_table(df_data, proto_df.data)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/elements/data_frame_proto.py", line 288, in _marshall_table _marshall_any_array(pandas_array, proto_table.cols.add())
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/elements/data_frame_proto.py", line 329, in _marshall_any_array raise NotImplementedError("Dtype %s not understood." % pandas_array.dtype) 

Is this a regression?

no

Debug info

  • Streamlit version: Streamlit, version 0.47.4
  • Python version: Python 3.7.4
  • Using Conda? PipEnv? PyEnv? Pex? Pip with virtualenv
  • OS version: Ubuntu 18.04.3 LTS running in WSL.
  • Browser version: Firefox, 69.0.2 (64-bit)

Additional information

Seems related to #47.

Metadata

Metadata

Assignees

Labels

area:arrowRelated to Arrow data serializationtype:enhancementRequests for feature enhancements or new features

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions