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
14 changes: 4 additions & 10 deletions sdm/tensor/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,12 @@ def _move_categories(
if device is None or device.type == "cpu":
return tuple(categories)

groups: dict[
tuple[type[Tensor], torch.dtype, torch.dtype | None], list[int]
] = defaultdict(list)
# Copy strings separately: views of a shared copy recompile per batch.
groups: dict[torch.dtype, list[int]] = defaultdict(list)
moved: list[Tensor | None] = [None] * len(categories)
for i, category in enumerate(categories):
if type(category) is Tensor or isinstance(category, StringTensor):
offset_dtype = (
category.data_offset[1].dtype
if isinstance(category, StringTensor)
else None
)
groups[(type(category), category.dtype, offset_dtype)].append(i)
if type(category) is Tensor:
groups[category.dtype].append(i)
else:
moved[i] = category.to(device)

Expand Down
1 change: 1 addition & 0 deletions test/tensor/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,7 @@ def test_from_pandas_nullable_and_categorical_dtypes(
assert all(
category.device == device for category in tensor.categorical.categories
)
assert tensor.categorical.categories[1].storage_offset() == 0
assert tensor.categorical.categories[0].tolist() == ["unused", "a", "b"]
assert tensor.categorical.categories[1].tolist() == ["b", "a"]
assert tensor.categorical.categories[2].tolist() == [True, False]
Expand Down
Loading