altair icon indicating copy to clipboard operation
altair copied to clipboard

`FutureWarning` with `pandas` 1.5.0

Open pharmpy-dev-123 opened this issue 3 years ago • 1 comments

Using .to_dict() on an altair 4.2.0 object I get the following FutureWarning with pandas 1.5.0:

.tox/py39-unit/lib/python3.9/site-packages/altair/vegalite/v4/api.py:384: in to_dict
    dct = super(TopLevelMixin, copy).to_dict(*args, **kwargs)
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/schemapi.py:326: in to_dict
    result = _todict(
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/schemapi.py:60: in _todict
    return {
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/schemapi.py:61: in <dictcomp>
    k: _todict(v, validate, context)
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/schemapi.py:58: in _todict
    return [_todict(v, validate, context) for v in obj]
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/schemapi.py:58: in <listcomp>
    return [_todict(v, validate, context) for v in obj]
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/schemapi.py:56: in _todict
    return obj.to_dict(validate=validate, context=context)
.tox/py39-unit/lib/python3.9/site-packages/altair/vegalite/v4/api.py:2020: in to_dict
    return super().to_dict(*args, **kwargs)
.tox/py39-unit/lib/python3.9/site-packages/altair/vegalite/v4/api.py:374: in to_dict
    copy.data = _prepare_data(original_data, context)
.tox/py39-unit/lib/python3.9/site-packages/altair/vegalite/v4/api.py:89: in _prepare_data
    data = _pipe(data, data_transformers.get())
.tox/py39-unit/lib/python3.9/site-packages/toolz/functoolz.py:628: in pipe
    data = func(data)
.tox/py39-unit/lib/python3.9/site-packages/toolz/functoolz.py:304: in __call__
    return self._partial(*args, **kwargs)
.tox/py39-unit/lib/python3.9/site-packages/altair/vegalite/data.py:19: in default_data_transformer
    return curried.pipe(data, limit_rows(max_rows=max_rows), to_values)
.tox/py39-unit/lib/python3.9/site-packages/toolz/functoolz.py:628: in pipe
    data = func(data)
.tox/py39-unit/lib/python3.9/site-packages/toolz/functoolz.py:304: in __call__
    return self._partial(*args, **kwargs)
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/data.py:149: in to_values
    data = sanitize_dataframe(data)
.tox/py39-unit/lib/python3.9/site-packages/altair/utils/core.py:317: in sanitize_dataframe
    for col_name, dtype in df.dtypes.iteritems():
.tox/py39-unit/lib/python3.9/site-packages/pandas/core/series.py:1845: in iteritems
    warnings.warn(
E   FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.

I believe it's just a matter of using .items() rather than .iteritems(). .items() was introduced for Python 3 only in https://github.com/pandas-dev/pandas/commit/16dbeaba9ec2cc6d87636981644a08cb9bb9b2cd and then for Python 2 in https://github.com/pandas-dev/pandas/commit/3b02e73b856a6f8d53382bf3908f04447bf90e03.

Since altair requires Python >= 3.7 this should not conflict with the current requirements of pandas>=0.18.

pharmpy-dev-123 avatar Oct 19 '22 10:10 pharmpy-dev-123

Thanks, A fix for this has been suggested in https://github.com/altair-viz/altair/pull/2683

joelostblom avatar Oct 19 '22 11:10 joelostblom