From ec8d594009b66586e204260fcc57bc3159689be3 Mon Sep 17 00:00:00 2001
From: Benjamin Kane <ben@voxel51.com>
Date: Tue, 28 May 2024 10:58:31 -0400
Subject: [PATCH] use view if possible, avoid len() call

---
 fiftyone/core/session/session.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/fiftyone/core/session/session.py b/fiftyone/core/session/session.py
index e761300113..2c6d49c04d 100644
--- a/fiftyone/core/session/session.py
+++ b/fiftyone/core/session/session.py
@@ -417,7 +417,7 @@ def __init__(
             view_name=final_view_name,
             spaces=spaces,
             color_scheme=build_color_scheme(color_scheme, dataset, config),
-            group_slice=(dataset.group_slice if dataset else None),
+            group_slice=_pull_group_slice(dataset, view),
         )
         self._client = fosc.Client(
             address=address,
@@ -1317,3 +1317,15 @@ def _on_refresh(session: Session, state: t.Optional[StateDescription]):
 
     if session.dataset is not None:
         session.dataset.reload()
+
+
+def _pull_group_slice(
+    dataset: t.Optional[fod.Dataset], view: t.Optional[fov.DatasetView]
+) -> t.Union[None, str]:
+    if view is not None:
+        return view.group_slice
+
+    if dataset is not None:
+        return dataset.group_slice
+
+    return None