Skip to content

Commit

Permalink
Always ravel array in unique_array (#5969)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Nov 3, 2023
1 parent 3adb998 commit 82dd07f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion holoviews/core/util.py
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
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
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

0 comments on commit 82dd07f

Please sign in to comment.