jcmgray / xyzpy

Efficiently generate and analyse high dimensional data.
http://xyzpy.readthedocs.io
MIT License
66 stars 11 forks source link

Merging case_runner crop fails #13

Closed AdrianSosic closed 2 years ago

AdrianSosic commented 3 years ago

Hi @jcmgray,

I noticed that crop.reap() fails when the there are several crops created by a Harvester that uses a case_runner instance. The reasons seems to be that case_runners return pandas DataFrames instead of xarray DataSets (unlike combo_runners) and hence the merge function is called on the resulting DataFrame object, which fails accordingly:

TypeError: merge() got an unexpected keyword argument 'compat'

My current workaround is to merge all cases manually so that I can avoid creating multiple crops in the first place.

jcmgray commented 3 years ago

Thanks for the issue @AdrianSosic - sounds like df.merge should not be called there. If you have a minimal working example then I can look into fixing it?

AdrianSosic commented 3 years ago

Sure =)

import pandas as pd
import xyzpy

def dummy_function(**args):
    return 0

cases1 = pd.DataFrame(
    [
        (1, 2),
        (3, 4),
    ],
    columns = ('a', 'b')
)

cases2 = pd.DataFrame(
    [
        (5, 6),
        (7, 8),
    ],
    columns = ('a', 'b')
)

runner = xyzpy.Runner(dummy_function, var_names=['Dummy_Value'])
harvester = xyzpy.Harvester(runner, engine='joblib')

crop1 = harvester.Crop()
crop1.sow_cases(fn_args=cases1.columns, cases=cases1.values.tolist())
crop1.grow_missing()
crop1.reap()

crop2 = harvester.Crop()
crop2.sow_cases(fn_args=cases2.columns, cases=cases2.values.tolist())
crop2.grow_missing()
crop2.reap()
jcmgray commented 3 years ago

I think sow_cases was introduced initially only as a method for sow_samples which indeed is meant to return a DataFrame but anyhow should be fixed by https://github.com/jcmgray/xyzpy/commit/c8f872df77015dcb830a2b02cbc60e017b9e8e8b, let me know if you run into any problems!

AdrianSosic commented 2 years ago

Works like a charm! At least I haven't seen any problems since then, so I think this issue can be closed. Thanks a lot =)