Skip to content

Preserve attrs on Dask DataFrame sample()#1088

Open
LiudengZhang wants to merge 1 commit intoscverse:mainfrom
LiudengZhang:fix/sample-preserve-attrs
Open

Preserve attrs on Dask DataFrame sample()#1088
LiudengZhang wants to merge 1 commit intoscverse:mainfrom
LiudengZhang:fix/sample-preserve-attrs

Conversation

@LiudengZhang
Copy link

Description

DaskDataFrame.sample() does not preserve .attrs metadata, unlike other wrapped methods (__getitem__, compute, copy, drop, map_partitions, set_index).

This adds "sample" to the list of methods wrapped by wrap_method_with_attrs in _accessor.py, so that .attrs is carried through after calling .sample().

Changes

  • Add "sample" to the wrapped methods list for DaskDataFrame in src/spatialdata/models/_accessor.py
  • Add test_dataframe_sample_preserves_attrs test following the existing test pattern

Test plan

  • pytest tests/models/test_accessor.py — all 20 tests pass (including new test)

Add "sample" to the list of wrapped methods in _accessor.py so that
calling .sample() on a Dask DataFrame retains its .attrs metadata,
consistent with the other wrapped methods.
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.96%. Comparing base (094b869) to head (0db2dfd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1088   +/-   ##
=======================================
  Coverage   91.96%   91.96%           
=======================================
  Files          51       51           
  Lines        7729     7729           
=======================================
  Hits         7108     7108           
  Misses        621      621           
Files with missing lines Coverage Δ
src/spatialdata/models/_accessor.py 90.14% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant