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

[BUG] Diviner is incompatible with pmdarima>=2.0.0 #14

Closed
harupy opened this issue Aug 24, 2022 · 2 comments
Closed

[BUG] Diviner is incompatible with pmdarima>=2.0.0 #14

harupy opened this issue Aug 24, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@harupy
Copy link

harupy commented Aug 24, 2022

pmdarima 2.0.0 broke diviner:

https://github.com/mlflow/mlflow/runs/7974149279?check_suite_focus=true#step:12:417

________________________ test_diviner_pyfunc_save_load _________________________

grouped_pmdarima = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
model_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_diviner_pyfunc_save_load0/model')

    def test_diviner_pyfunc_save_load(grouped_pmdarima, model_path):
    
        mlflow.diviner.save_model(diviner_model=grouped_pmdarima, path=model_path)
        loaded_pyfunc = pyfunc.load_pyfunc(model_uri=model_path)
    
>       model_predict = grouped_pmdarima.predict(n_periods=10, return_conf_int=True, alpha=0.075)

grouped_pmdarima = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
loaded_pyfunc = mlflow.pyfunc.loaded_model:
  flavor: mlflow.diviner

model_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_diviner_pyfunc_save_load0/model')

tests/diviner/test_diviner_model_export.py:98: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:405: in predict
    return self._run_predictions(prediction_config, exog=exog, **predict_kwargs)
        alpha      = 0.075
        exog       = None
        inverse_transform = True
        n_periods  = 10
        predict_col = 'yhat'
        predict_kwargs = {}
        prediction_config =    n_periods  alpha  return_conf_int  inverse_transform key2 key1 key0
0         10  0.075             True           ...          True               True    L    A    K
3         10  0.075             True               True    Z    X    B
        return_conf_int = True
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:335: in _run_predictions
    for idx, row in processing_data.iterrows()
        df         =    n_periods  alpha  return_conf_int  inverse_transform key2 key1 key0
0         10  0.075             True           ...          True               True    L    A    K
3         10  0.075             True               True    Z    X    B
        exog       = None
        n_periods_col = 'n_periods'
        predict_kwargs = {}
        processing_data =    n_periods  alpha  return_conf_int  ...  key1 key0 grouping_key
0         10  0.075             True  ...     P    T...ue  ...     A    K    (L, A, K)
3         10  0.075             True  ...     X    B    (Z, X, B)

[4 rows x 8 columns]
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:335: in <listcomp>
    for idx, row in processing_data.iterrows()
        .0         = <generator object DataFrame.iterrows at 0x7fddfef0a6d0>
        exog       = None
        idx        = 0
        n_periods_col = 'n_periods'
        predict_kwargs = {}
        row        = n_periods                   10
alpha                    0.075
return_conf_int           True
inverse_transform        ...  H
key1                         P
key0                         T
grouping_key         (H, P, T)
Name: 0, dtype: object
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:301: in _predict_single_group
    **predict_kwargs,
        alpha      = 0.075
        exog       = None
        group_key  = ('H', 'P', 'T')
        inverse_transform = True
        model      = AutoARIMA(maxiter=30, out_of_sample_size=60)
        n_periods_col = 'n_periods'
        periods    = 10
        predict_kwargs = {}
        return_conf_int = True
        row_entry  = n_periods                   10
alpha                    0.075
return_conf_int           True
inverse_transform        ...  H
key1                         P
key0                         T
grouping_key         (H, P, T)
Name: 0, dtype: object
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = ()
kwargs = {'X': None, 'alpha': 0.075, 'inverse_transform': True, 'n_periods': 10, ...}

>   out = (lambda *args, **kwargs: self.fn(obj, *args, **kwargs))
E   TypeError: predict() got an unexpected keyword argument 'inverse_transform'

args       = ()
kwargs     = {'X': None, 'alpha': 0.075, 'inverse_transform': True, 'n_periods': 10, ...}
obj        = AutoARIMA(maxiter=30, out_of_sample_size=60)
self       = <pmdarima.utils.metaestimators._IffHasDelegate object at 0x7fde0085e350>

/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pmdarima/utils/metaestimators.py:53: TypeError
__________________ test_diviner_pyfunc_group_predict_pmdarima __________________

grouped_pmdarima = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
model_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_diviner_pyfunc_group_pred1/model')
diviner_data = Structure(df=                      ds           y key2 key1 key0
0    2019-01-01 00:01:00  946.607797    J    Z    G
1...  T
1[45](https://github.com/mlflow/mlflow/runs/7974149279?check_suite_focus=true#step:12:46)9 2022-12-30 00:01:00  435.780587    H    P    T

[5840 rows x 5 columns], key_columns=['key2', 'key1', 'key0'])

    def test_diviner_pyfunc_group_predict_pmdarima(grouped_pmdarima, model_path, diviner_data):
    
        groups = []
        for i in [0, -1]:
            key_entries = []
            for value in diviner_data.df[diviner_data.key_columns].iloc[[i]].to_dict().values():
                key_entries.append(list(value.values())[0])
            groups.append(tuple(key_entries))
    
        mlflow.diviner.save_model(diviner_model=grouped_pmdarima, path=model_path)
        loaded_pyfunc_model = pyfunc.load_pyfunc(model_uri=model_path)
    
        local_group_pred = grouped_pmdarima.predict_groups(
            groups=groups,
            n_periods=10,
            predict_col="prediction",
            alpha=0.1,
            return_conf_int=True,
>           on_error="warn",
        )

diviner_data = Structure(df=                      ds           y key2 key1 key0
0    2019-01-01 00:01:00  9[46](https://github.com/mlflow/mlflow/runs/7974149279?check_suite_focus=true#step:12:47).607797    J    Z    G
1...  T
1459 2022-12-30 00:01:00  435.780587    H    P    T

[5840 rows x 5 columns], key_columns=['key2', 'key1', 'key0'])
grouped_pmdarima = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
groups     = [('J', 'Z', 'G'), ('H', 'P', 'T')]
i          = -1
key_entries = ['H', 'P', 'T']
loaded_pyfunc_model = mlflow.pyfunc.loaded_model:
  flavor: mlflow.diviner

model_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_diviner_pyfunc_group_pred1/model')
value      = {1459: 'T'}

tests/diviner/test_diviner_model_export.py:179: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:[48](https://github.com/mlflow/mlflow/runs/7974149279?check_suite_focus=true#step:12:49)6: in predict_groups
    return self._run_predictions(prediction_config, exog=exog, **predict_kwargs)
        alpha      = 0.1
        exog       = None
        groups     = [('J', 'Z', 'G'), ('H', 'P', 'T')]
        inverse_transform = False
        n_periods  = 10
        on_error   = 'warn'
        predict_col = 'prediction'
        predict_kwargs = {}
        prediction_config =    n_periods  alpha  return_conf_int  inverse_transform key2 key1 key0
0         10    0.1             True              False    H    P    T
1         10    0.1             True              False    J    Z    G
        return_conf_int = True
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:335: in _run_predictions
    for idx, row in processing_data.iterrows()
        df         =    n_periods  alpha  return_conf_int  inverse_transform key2 key1 key0
0         10    0.1             True              False    H    P    T
1         10    0.1             True              False    J    Z    G
        exog       = None
        n_periods_col = 'n_periods'
        predict_kwargs = {}
        processing_data =    n_periods  alpha  return_conf_int  ...  key1 key0 grouping_key
0         10    0.1             True  ...     P    T    (H, P, T)
1         10    0.1             True  ...     Z    G    (J, Z, G)

[2 rows x 8 columns]
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:335: in <listcomp>
    for idx, row in processing_data.iterrows()
        .0         = <generator object DataFrame.iterrows at 0x7fddfeca86[50](https://github.com/mlflow/mlflow/runs/7974149279?check_suite_focus=true#step:12:51)>
        exog       = None
        idx        = 0
        n_periods_col = 'n_periods'
        predict_kwargs = {}
        row        = n_periods                   10
alpha                      0.1
return_conf_int           True
inverse_transform        ...  H
key1                         P
key0                         T
grouping_key         (H, P, T)
Name: 0, dtype: object
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:301: in _predict_single_group
    **predict_kwargs,
        alpha      = 0.1
        exog       = None
        group_key  = ('H', 'P', 'T')
        inverse_transform = False
        model      = AutoARIMA(maxiter=30, out_of_sample_size=60)
        n_periods_col = 'n_periods'
        periods    = 10
        predict_kwargs = {}
        return_conf_int = True
        row_entry  = n_periods                   10
alpha                      0.1
return_conf_int           True
inverse_transform        ...  H
key1                         P
key0                         T
grouping_key         (H, P, T)
Name: 0, dtype: object
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = ()
kwargs = {'X': None, 'alpha': 0.1, 'inverse_transform': False, 'n_periods': 10, ...}

>   out = (lambda *args, **kwargs: self.fn(obj, *args, **kwargs))
E   TypeError: predict() got an unexpected keyword argument 'inverse_transform'

args       = ()
kwargs     = {'X': None, 'alpha': 0.1, 'inverse_transform': False, 'n_periods': 10, ...}
obj        = AutoARIMA(maxiter=30, out_of_sample_size=60)
self       = <pmdarima.utils.metaestimators._IffHasDelegate object at 0x7fde0085e350>

/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pmdarima/utils/metaestimators.py:53: TypeError
__________________ test_diviner_load_from_remote_uri_succeeds __________________

grouped_pmdarima = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
model_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_diviner_load_from_remote_0/model')
mock_s3_bucket = 'mock-bucket'

    def test_diviner_load_from_remote_uri_succeeds(grouped_pmdarima, model_path, mock_s3_bucket):
        mlflow.diviner.save_model(diviner_model=grouped_pmdarima, path=model_path)
    
        artifact_root = f"s3://{mock_s3_bucket}"
        artifact_path = "model"
        artifact_repo = S3ArtifactRepository(artifact_root)
        artifact_repo.log_artifacts(model_path, artifact_path=artifact_path)
    
        # NB: cloudpathlib would need to be used here to handle object store uri
        model_uri = os.path.join(artifact_root, artifact_path)
        reloaded_model = mlflow.diviner.load_model(model_uri=model_uri)
    
>       pd.testing.assert_frame_equal(grouped_pmdarima.predict(10), reloaded_model.predict(10))

artifact_path = 'model'
artifact_repo = <mlflow.store.artifact.s3_artifact_repo.S3ArtifactRepository object at 0x7fddf8a65d90>
artifact_root = 's3://mock-bucket'
grouped_pmdarima = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
mock_s3_bucket = 'mock-bucket'
model_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_diviner_load_from_remote_0/model')
model_uri  = 's3://mock-bucket/model'
reloaded_model = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddf8a65f10>

tests/diviner/test_diviner_model_export.py:232: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:405: in predict
    return self._run_predictions(prediction_config, exog=exog, **predict_kwargs)
        alpha      = 0.05
        exog       = None
        inverse_transform = True
        n_periods  = 10
        predict_col = 'yhat'
        predict_kwargs = {}
        prediction_config =    n_periods  alpha  return_conf_int  inverse_transform key2 key1 key0
0         10   0.05            False           ...         False               True    L    A    K
3         10   0.05            False               True    Z    X    B
        return_conf_int = False
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:335: in _run_predictions
    for idx, row in processing_data.iterrows()
        df         =    n_periods  alpha  return_conf_int  inverse_transform key2 key1 key0
0         10   0.05            False           ...         False               True    L    A    K
3         10   0.05            False               True    Z    X    B
        exog       = None
        n_periods_col = 'n_periods'
        predict_kwargs = {}
        processing_data =    n_periods  alpha  return_conf_int  ...  key1 key0 grouping_key
0         10   0.05            False  ...     P    T...se  ...     A    K    (L, A, K)
3         10   0.05            False  ...     X    B    (Z, X, B)

[4 rows x 8 columns]
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:335: in <listcomp>
    for idx, row in processing_data.iterrows()
        .0         = <generator object DataFrame.iterrows at 0x7fddf8aa8ed0>
        exog       = None
        idx        = 0
        n_periods_col = 'n_periods'
        predict_kwargs = {}
        row        = n_periods                   10
alpha                     0.05
return_conf_int          False
inverse_transform        ...  H
key1                         P
key0                         T
grouping_key         (H, P, T)
Name: 0, dtype: object
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/diviner/grouped_pmdarima.py:301: in _predict_single_group
    **predict_kwargs,
        alpha      = 0.05
        exog       = None
        group_key  = ('H', 'P', 'T')
        inverse_transform = True
        model      = AutoARIMA(maxiter=30, out_of_sample_size=60)
        n_periods_col = 'n_periods'
        periods    = 10
        predict_kwargs = {}
        return_conf_int = False
        row_entry  = n_periods                   10
alpha                     0.05
return_conf_int          False
inverse_transform        ...  H
key1                         P
key0                         T
grouping_key         (H, P, T)
Name: 0, dtype: object
        self       = <diviner.grouped_pmdarima.GroupedPmdarima object at 0x7fddff924a90>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = ()
kwargs = {'X': None, 'alpha': 0.05, 'inverse_transform': True, 'n_periods': 10, ...}

>   out = (lambda *args, **kwargs: self.fn(obj, *args, **kwargs))
E   TypeError: predict() got an unexpected keyword argument 'inverse_transform'

args       = ()
kwargs     = {'X': None, 'alpha': 0.05, 'inverse_transform': True, 'n_periods': 10, ...}
obj        = AutoARIMA(maxiter=30, out_of_sample_size=60)
self       = <pmdarima.utils.metaestimators._IffHasDelegate object at 0x7fde0085e350>

/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pmdarima/utils/metaestimators.py:[53](https://github.com/mlflow/mlflow/runs/7974149279?check_suite_focus=true#step:12:54): TypeError
@harupy harupy added the bug Something isn't working label Aug 24, 2022
@harupy
Copy link
Author

harupy commented Aug 24, 2022

Related to alkaline-ml/pmdarima#494, which removed **kwargs in AutoArima.predict.

@BenWilson2
Copy link
Collaborator

Fixed in #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants