Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: use the option framework to opt-out of auto-alignment #61075

Open
1 of 3 tasks
jxrossel opened this issue Mar 7, 2025 · 0 comments
Open
1 of 3 tasks

ENH: use the option framework to opt-out of auto-alignment #61075

jxrossel opened this issue Mar 7, 2025 · 0 comments
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@jxrossel
Copy link

jxrossel commented Mar 7, 2025

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

As far as I know, auto-alignment of DataFrames and Series (e.g. with arithmetic operations) cannot be disabled. To work in "strict" mode, the user must first check alignment and then make a computation:

a = pd.DataFrame(...)
b = pd.DataFrame(...)

c = pd.Series(...)
d = pd.Series(...)

if not a.index.equals(b.index) or not a.columns.equals(b.columns):
    raise ...
k = a + b

if not c.index.equals(d.index):
    raise ...
m = c + d

Since alignment must also be checked internally by pandas, this is not only cumbersome but inefficient.

Feature Description

Use the pandas option framework to opt-out of auto-alignment. One could even go one step further to allow deactivation of alignment check altogether for data that is known to be aligned (to gain some computation time). So the option would look like: mode.on_misaligned:

  • coerce: default and current behaviour
  • raise: strict mode, raise an error if indices are not aligned
  • ignore: skip alignment checking and proceed with the computation assuming data is already aligned
    The user would then set the option as he sees fit, e.g. with a context manager:
with pd.option_context("mode.on_misaligned", "raise"):
    k = a + b
    m = c + d

Alternative Solutions

The alternative solution is the problem

Additional Context

No response

@jxrossel jxrossel added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant