Skip to content

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

Open
@jxrossel

Description

@jxrossel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions