Skip to content

Commit 0af36e4

Browse files
committed
move_dims: better no-op handling
1 parent f72dab3 commit 0af36e4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

namedisl/core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,15 @@ def move_dims(
824824

825825
obj = self._obj
826826

827+
did_something = False
828+
827829
for source_dt, chunks in chunked_dims_by_type(
828830
names, self.space.name_to_dim).items():
829831
for start, count in chunks[::-1]:
830832
if dest_dt == source_dt:
831833
continue
832834

835+
did_something = True
833836
del new_dimtype_to_names[source_dt][start:start+count]
834837
new_dimtype_to_names[dest_dt].extend(self.space.dimtype_to_names[source_dt][start:start+count])
835838
isl_dest_dt = dest_dt.as_isl()
@@ -848,10 +851,13 @@ def move_dims(
848851
source_dt.as_isl(), start,
849852
count))
850853

851-
return type(self)(obj, Space(constantdict({
852-
dt: tuple(names)
853-
for dt, names in new_dimtype_to_names.items()
854-
})))
854+
if did_something:
855+
return type(self)(obj, Space(constantdict({
856+
dt: tuple(names)
857+
for dt, names in new_dimtype_to_names.items()
858+
})))
859+
else:
860+
return self
855861

856862
def rename_dims(self, renaming: Iterable[tuple[str, str]]) -> Self:
857863
if not renaming:

0 commit comments

Comments
 (0)