Skip to content

BUG: KeyMap has a failure with pandas 3.0.3 #1329

@VisLab

Description

@VisLab

Issue: KeyMap._remap() ValueError on pandas 3.0.3

KeyMap._remap() fails with ValueError: Length of values (2) does not match length of index (0) on pandas 3.0.3


Exact Reproduction Case

Input Data

import pandas as pd

# Test DataFrame - exactly as used in test_numeric_keys_cascade
df = pd.DataFrame({
    'test': [1, 2, 'n/a', 3, 4, 5],
    'response_accuracy': ['correct', 'correct', 'correct', 'n/a', 'correct', 'correct'],
    'response_hand': ['right', 'right', 'right', 'n/a', 'left', 'left']
})

print("Input DataFrame:")
print(df)
print("\nDataFrame dtypes:")
print(df.dtypes)
print("\nDataFrame shape:", df.shape)

Output:

Input DataFrame:
  test response_accuracy response_hand
0    1            correct         right
1    2            correct         right
2  n/a            correct         right
3    3                n/a           n/a
4    4            correct          left
5    5            correct          left

DataFrame dtypes:
test                  object
response_accuracy     object
response_hand         object
dtype: object

DataFrame shape: (6, 3)

Operation Configuration

from hed.tools.analysis.key_map import KeyMap

# Remap configuration - cascading numeric keys
# Maps: 1→"correct_left", 2→"correct_right" for test column
map_list = [
    [1, 1, "correct_left"],      # When test=1 AND response_accuracy=1, create "correct_left"
    [2, 2, "correct_right"]      # When test=2 AND response_accuracy=2, create "correct_right"
]

key_map = KeyMap(
    source_columns=['test'],
    map_list=map_list
)

# This is where it fails
df_remapped, missing = key_map.remap(df)

Exact Error

On pandas 3.0.3 (FAILS):

ValueError: Length of values (2) does not match length of index (0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions