Skip to content

Conversation

timtreis
Copy link
Member

@timtreis timtreis commented Apr 2, 2025

No description provided.

@timtreis timtreis linked an issue Apr 2, 2025 that may be closed by this pull request
Copy link

codecov bot commented Apr 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.15%. Comparing base (872f8c2) to head (5c5fb38).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #919   +/-   ##
=======================================
  Coverage   92.14%   92.15%           
=======================================
  Files          48       48           
  Lines        7473     7479    +6     
=======================================
+ Hits         6886     6892    +6     
  Misses        587      587           
Files with missing lines Coverage Δ
src/spatialdata/_core/concatenate.py 92.42% <100.00%> (+0.36%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis requested a review from Copilot May 18, 2025 16:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new merge_coordinate_systems_on_name flag to sd.concatenate, allowing users to control whether coordinate systems with the same name are merged or given distinct suffixes.
Key changes:

  • Add merge_coordinate_systems_on_name parameter to concatenate API and forward it to the renaming helper.
  • Update _fix_ensure_unique_element_names to propagate transformations and apply suffixes (or not) based on the new flag.
  • Add a parametrized test in test_concatenate_merge_coordinate_systems_on_name to verify both behaviors.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/core/test_concatenate.py New test test_concatenate_merge_coordinate_systems_on_name checks merged vs. suffixed CS names.
src/spatialdata/_core/concatenate.py - Added merge_coordinate_systems_on_name to signature and doc.\n- Enhanced _fix_ensure_unique_element_names to handle CS transformations.

@timtreis timtreis requested a review from Copilot May 18, 2025 16:21
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new parameter, merge_coordinate_systems_on_name, to sd.concatenate in order to control whether coordinate system names are merged (i.e. kept unchanged) or suffixed with a key.

  • Adds merge_coordinate_systems_on_name to both the public concatenate function and the internal _fix_ensure_unique_element_names helper.
  • Updates the test suite to verify that coordinate system names are handled as expected based on the parameter value.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/core/test_concatenate.py New test verifying the behavior of merge_coordinate_systems_on_name in concatenated outputs.
src/spatialdata/_core/concatenate.py Updates to function signatures and implementation to support the merge_coordinate_systems_on_name flag.

@timtreis timtreis requested a review from LucaMarconato May 18, 2025 16:47
modify_tables_inplace: bool,
merge_coordinate_systems_on_name: bool,
) -> list[SpatialData]:
elements_by_sdata: list[dict[str, SpatialElement]] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this refactoring is fine

# Handle coordinate systems and transformations
for element_name, element in elements.items():
# Get the original element from the input sdata
original_name = element_name.replace(f"-{suffix}", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this, we already know el when constructing the elements dict.

raise TypeError(f"Expected 'transformations' to be a dict, but got {type(transformations).__name__}.")

# Remove any existing transformations from the new element
remove_transformation(element, remove_all=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code removes all the transformations, then checks (at every iteration) for the value of merge_coordinate_system_on_name, and when it is true it restores the original transformation.

This is convoluted and note needed, as one could check merge_coordinate_system_on_name before calling remove_transformation.

@@ -0,0 +1,36 @@
import pytest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests for concatenate are in test_spatialdata_operations.py, I will move this code there.

@LucaMarconato
Copy link
Member

@timtreis I gave comments on the code and committed the suggestions that I made during review. Please have a look at the changes and if you are happy with them we can merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sd.concatenate doesn't apply suffix to coordinate systems
2 participants