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

Always ravel array in unique_array #5969

Merged
merged 2 commits into from
Nov 3, 2023
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
4 changes: 3 additions & 1 deletion holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,10 @@ def unique_array(arr):
if (isinstance(v, datetime_types) and
not isinstance(v, cftime_types)):
v = pd.Timestamp(v).to_datetime64()
elif isinstance(getattr(v, "dtype", None), pd.CategoricalDtype):
v = v.dtype.categories
values.append(v)
return pd.unique(np.asarray(values))
return pd.unique(np.asarray(values).ravel())


def match_spec(element, specification):
Expand Down
7 changes: 7 additions & 0 deletions holoviews/tests/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
sanitize_identifier_fn,
search_indices,
tree_attribute,
unique_array,
wrap_tuple_streams,
)
from holoviews.element.comparison import ComparisonTestCase
Expand Down Expand Up @@ -799,3 +800,9 @@ def test_seach_indices_dtype_object():
values = np.array(["c0", "c0", np.nan], dtype=object)
source = np.array(["c0", np.nan], dtype=object)
search_indices(values, source)


def test_unique_array_categorial():
ser = pd.Series(np.random.choice(["a", "b", "c"], 100)).astype("category")
res = unique_array([ser])
assert sorted(res) == ["a", "b", "c"]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ known-first-party = ["holoviews"]
combine-as-imports = true

[tool.codespell]
ignore-words-list = "lod,nd,ndoes,reenabled,spreaded,whn"
ignore-words-list = "lod,nd,ndoes,reenabled,spreaded,whn,ser"
skip = "doc/generate_modules.py"
write-changes = true