Skip to content

Decouple DLC dataframe format from split_individuals in to_dlc_file (revives feature from #314, replaces stale PR #529)#883

Open
swagat-mishra28 wants to merge 5 commits intoneuroinformatics-unit:mainfrom
swagat-mishra28:fix-save-poses-bug
Open

Decouple DLC dataframe format from split_individuals in to_dlc_file (revives feature from #314, replaces stale PR #529)#883
swagat-mishra28 wants to merge 5 commits intoneuroinformatics-unit:mainfrom
swagat-mishra28:fix-save-poses-bug

Conversation

@swagat-mishra28
Copy link

Related Issue

Fixes #314

This PR reintroduces the feature originally attempted in PR #529, which was closed after becoming stale. The goal of the issue is to decouple two behaviors that are currently tied together in the split_individuals argument of save_poses.to_dlc_file().

Background

Currently, the split_individuals argument controls two independent behaviors simultaneously:

  1. Whether individuals are written to separate files

  2. Which DeepLabCut dataframe format is used

  • Single-animal format (< DLC 2.0)

  • Multi-animal format (>= DLC 2.0)

Because these two behaviors are coupled, users cannot independently control:

  • the file splitting strategy
  • the DeepLabCut dataframe format

For example, it is currently not possible to:

save one file per individual while still using the modern multi-animal DLC dataframe format.

Several workflows (including compatibility with tools expecting the DLC >=2.0 format) benefit from being able to control these behaviors independently.

Proposed Solution

This PR introduces a new argument to explicitly control the DLC dataframe format:

dlc_df_format: Literal["single-animal", "multi-animal"] = "multi-animal"

Updated function signature:

def to_dlc_file(
ds: xarray.Dataset,
file_path: str | Path,
split_individuals: bool = False,
dlc_df_format: Literal["single-animal", "multi-animal"] = "multi-animal",

This separates the two previously coupled behaviors:

Argument Responsibility
split_individuals Whether individuals are written to separate files
dlc_df_format Which DLC dataframe format is used

Default Behavior

The default behavior remains fully backward compatible:

split_individuals = False

dlc_df_format = "multi-animal"

This produces a single output file using the modern DLC >=2.0 dataframe format, which is general enough to support both single- and multi-animal datasets.

Implementation Details

The implementation focuses on a minimal and clean change set:

  1. Introduced the new dlc_df_format parameter.

2.Updated the internal dataframe generation logic in to_dlc_style_df.

  1. Ensured correct handling of both:
  • single-individual datasets
  • multi-individual datasets

4.Preserved the existing dataset validation behavior.

  1. Avoided introducing unrelated changes that were present in the previous PR (Splitting_Individuals_and_DLC_Format  #529).

Tests

Relevant tests in tests/test_unit/test_save_poses.py were updated to reflect the new parameter and to verify:

  • correct dataframe format generation
  • correct file splitting behavior
  • compatibility with both dataset types

Full test suite results:

1027 passed, 4 deselected, 2 xfailed

Coverage remains unchanged:

87% total coverage

Notes

  • This PR intentionally keeps the scope minimal to focus only on the requested feature.

  • It supersedes the previous attempt in PR Splitting_Individuals_and_DLC_Format  #529 while preserving the original design idea.

  • No breaking API changes were introduced; the new parameter has a sensible default.

@swagat-mishra28
Copy link
Author

Hi @niksirbi,

This PR implements the feature requested in #314 and revives the earlier attempt from #529.

It looks like the CI workflows are currently awaiting maintainer approval. Once approved, the remaining checks should run.

Please let me know if any adjustments are needed. Thanks !

@swagat-mishra28
Copy link
Author

Hi @niksirbi,

I've resolved the linting and mypy issues that were causing the CI failures and pushed the fixes.
Please let me know if any additional adjustments are needed. Thanks!

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

Rethink splitting of individuals in save_poses.to_dlc_file()

1 participant