question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pandas categories support not implemented

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
vitorbaptistacommented, Mar 10, 2020

Any ETA on when Streamlit will support displaying categorical variables?

2reactions
andresaklecommented, Jun 11, 2020

Workaround from a related issue: st.write(df.astype(‘object’))

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using pandas categories properly is tricky... here's why
Pandas category errors, categories turn to strings, category merges change datatypes, empty groups when groupby on cats.
Read more >
Categorical data — pandas 1.5.2 documentation
All values of categorical data are either in categories or np.nan . Order is defined by the order of categories , not lexical...
Read more >
Pandas Categorical data type not behaving as expected
I want to make the code column an ordered variable of type Categorical after the df creation as below. import pandas as pd...
Read more >
Using The Pandas Category Data Type
Introduction to pandas categorical data type and how to use it.
Read more >
Type Support in Pandas API on Spark — PySpark 3.3.1 ...
These kind of pandas specific data types below are not currently supported in pandas API on Spark but planned to be supported. pd.Timedelta....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found