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

tweak accessor to accept numpy dict #985

Merged
merged 1 commit into from
Mar 27, 2020
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
2 changes: 1 addition & 1 deletion python/perspective/perspective/table/_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, data_or_schema):

dtype = array.dtype

if name == "index" and isinstance(data_or_schema.index, pandas.DatetimeIndex):
if name == "index" and hasattr(data_or_schema, "index") and isinstance(data_or_schema.index, pandas.DatetimeIndex):
# use the index of the original, unflattened dataframe
dtype = _parse_datetime_index(data_or_schema.index)

Expand Down
11 changes: 10 additions & 1 deletion python/perspective/perspective/tests/table/test_update_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,13 @@ def test_update_np_nan_partial(self):
assert tbl.view().to_dict() == {
"a": [None, 2, None],
"b": ["a", "b", "c"]
}
}

def test_numpy_dict(self):
x = {"index": [1], "a": np.empty((1,), str)}
tbl = Table({"index": int, "a": str}, index='index')
tbl.update({"index": np.arange(5)})
assert tbl.view().to_dict() == {
"index": list(range(5)),
"a": [None for _ in range(5)]
}