Skip to content

Lookup function does not return default value with dataframes #4048

@tdayris

Description

@tdayris

Hi all,

Snakemake version

9.16.2

Describe the bug

While searching content within a pandas.DataFrame with the function lookup, if there is no row matching results, then default value should be returned. It is not.

Logs

See example below.

Minimal example

The following dummy example does not even require to run Snakemake itself and can be used in a python console. However, the very same behavior occurs within a Snakefile.

import pandas as pd
import numpy as np
import snakemake.ioutils as siou

df = pd.DataFrame(
    [
         [np.nan, 2.0,],
         [3.0,    4.0,],
         [np.nan, np.nan,],
         [np.nan, 3.0,],
     ], 
)
df.columns=["Zero", "One",]
siou.lookup(query=f"Zero == 4.0", within=df, default=5.0)

This returns [] and not 5.0

Additional context

When looking into dictionaries, everything works fine and default value is returned.

Thanks in advance for your insight

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions