Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/perspective/perspective/core/data/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def deconstruct_pandas(data, kwargs=None):
if isinstance(v, pd.CategoricalDtype):
data[k] = data[k].astype(str)

# convert StringDtype to str
if isinstance(data, pd.DataFrame) and hasattr(pd, "StringDtype"):
for k, v in data.dtypes.items():
if isinstance(v, pd.StringDtype):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe this was meant to be used in the hasattr, hasattr(pd, "StringDType") since StringDType is the new type

data[k] = data[k].astype(str)

if isinstance(data, pd.DataFrame) and isinstance(data.columns, pd.MultiIndex) and isinstance(data.index, pd.MultiIndex):
# Row and col pivots
kwargs["group_by"].extend([str(c) for c in data.index.names])
Expand Down
12 changes: 12 additions & 0 deletions python/perspective/perspective/tests/table/test_table_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,15 @@ def test_splitbys(self):
df_both = pd.DataFrame(np.random.randn(3, 16), index=["A", "B", "C"], columns=index)
table = Table(df_both)
assert table.size() == 48

def test_table_dataframe_for_dtype_equals_string(self):
df = pd.DataFrame({"a": ["aa", "bbb"], "b": ["dddd", "dd"]}, dtype="string")
table = Table(df)
view = table.view()

assert table.size() == 2

assert table.schema() == {"index": int, "a": str, "b": str}

view_df = view.to_df()
assert view_df.to_dict() == {"index": {0: 0, 1: 1}, "a": {0: "aa", 1: "bbb"}, "b": {0: "dddd", 1: "dd"}}