Skip to content

Conversation

sfc-gh-joshi
Copy link
Contributor

What do these changes do?

Currently, DataFrame.T is declared like so:

    def transpose(self, copy=False, *args) -> DataFrame:  # noqa: PR01, RT01, D200
        """
        Transpose index and columns.
        """
        # FIXME: Judging by pandas docs `*args` serves only compatibility purpose
        # and does not affect the result, we shouldn't pass it to the query compiler.
        return self.__constructor__(
            query_compiler=self._query_compiler.transpose(*args)
        )

    T: DataFrame = property(transpose)

This breaks automatic backend switching in a very subtle way. Because we use the QueryCompilerCaster ABC to replace all methods with a wrapper that picks the correct backend, the transpose referenced in property(transpose) is actually the original, unwrapped method, and therefore never uses the switching code path. This PR replaces the definition of T with

    @property
    def T(self):
        return self.transpose()

which defers lookup of transpose to runtime, and therefore uses the caster wrapper correctly.

I initially attempted to add special logic to wrap fget/fset/fdel or property objects in QueryCompilerCaster, but this became complicated and also didn't work for some reason--somehow, even though I was able to wrap fget, the wrapped function was never called. The approach in this PR is simpler, and runs a lower risk of breaking behavior or accidentally causing thrashing for other commonly-accessed properties like columns and index.

  • first commit message and PR title follow format outlined here

    NOTE: If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.

  • passes flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py
  • passes black --check modin/ asv_bench/benchmarks scripts/doc_checker.py
  • signed commit with git commit -s
  • Resolves BUG: Properties (like df.T) are not treated as switch points with AutoSwitchBackend #7653
  • tests added and passing
  • module layout described at docs/development/architecture.rst is up-to-date

Copy link
Contributor

@sfc-gh-jkew sfc-gh-jkew left a comment

Choose a reason for hiding this comment

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

Makes sense to me

@sfc-gh-joshi sfc-gh-joshi merged commit 8d468dc into modin-project:main Aug 27, 2025
40 checks passed
@sfc-gh-joshi sfc-gh-joshi deleted the joshi/property-switch branch August 27, 2025 21:07
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.

BUG: Properties (like df.T) are not treated as switch points with AutoSwitchBackend

2 participants