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

Use .items instead (Python 3.11) #2723

Closed
4 tasks done
berryny opened this issue Nov 23, 2022 · 13 comments
Closed
4 tasks done

Use .items instead (Python 3.11) #2723

berryny opened this issue Nov 23, 2022 · 13 comments
Labels

Comments

@berryny
Copy link

berryny commented Nov 23, 2022

I wrote the code below which can be found here

#make a bar graph of the df using Altair
alt.Chart(df).mark_bar().encode(
    x = 'community_board', #x axis is encoded by the Bronx community boards
    y='count()',
)

The graphic appears in Visual Code Notebook however VS and github displays the below error message

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/altair/utils/core.py:317: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
  for col_name, dtype in df.dtypes.iteritems():

Thoughts?

Please follow these steps to make it more efficient to solve your issue:

  • Since Altair is a Python wrapper around the Vega-Lite visualization grammar, most bugs should be reported directly to Vega-Lite. You can click the Action Button of your Altair chart and "Open in Vega Editor" to create a reproducible Vega-Lite example and see if you get the same error in the Vega Editor.
  • Search for duplicate issues.
  • Use the latest version of Altair.
  • Describe how to reproduce the bug and include the full code and data to reproduce it, ideally using a sample data set from vega_datasets.
@berryny berryny added the bug label Nov 23, 2022
@mattijn
Copy link
Contributor

mattijn commented Nov 23, 2022

Fixed in #2683

@mattijn mattijn closed this as completed Nov 23, 2022
@berryny
Copy link
Author

berryny commented Nov 23, 2022

I don't understand how to issue was resolved when it still appears on GitHub.

@mattijn
Copy link
Contributor

mattijn commented Nov 29, 2022

The issue you describe has been fixed.
You can install the main repo of Altair from GitHub or wait until a new version is released.

@simiaolin
Copy link

Hi Martijn, is there an approximate date for the new version to be released?

@mattijn
Copy link
Contributor

mattijn commented Dec 6, 2022

My hope: official release, early 2023 and a first release candidate this year.

@ChristopherDavisUCI
Copy link
Contributor

@mattijn @joelostblom Would it make sense to have a mini-release (like 4.2.1) fixing this iteritems issue but not adding all the other Altair 5 bells and whistles? Not sure if that's even possible or not.

@joelostblom
Copy link
Contributor

Sorry missed to reply here. I think a minor release would be nice in theory, but probably not worth the effort since we would need to sort out which commits should go into it and maybe even rebase the main repo to reorder the commits accordingly since we have added all new functionality into the main branch right now. I think our time is better spent fixing the outstanding issues for the next major release.

@joelostblom
Copy link
Contributor

@simiaolin @berryny There is now a release candidate of Altair 5, which supports Vega-Lite 5! Details and info on how to install can be found in #2937

@ragunyrasta
Copy link

I'm still encountering this bug in Altair 5.1.2.

@joelostblom
Copy link
Contributor

iteritems is no longer used anywhere within the altair code base. Could you please post your full error message and include the versions of pandas and altair.

@mbbau
Copy link

mbbau commented Jan 29, 2024

Hello everyone. I am having the same issue with Altair 5.2.0 and Pandas 2.2.0. .
Here is a sample code from the Altair Gallery:

import Altair as alt
import numpy as np
import pandas as pd

x = np.arange(100)
source = pd.DataFrame({
'x': x,
'f(x)': np.sin(x / 5)
})

alt.Chart(source).mark_line().encode(
x='x',
y='f(x)'
)

Here is the error message:


AttributeError Traceback (most recent call last)
c:\Users\usuario\AppData\Local\Programs\Python\Python311\Lib\site-packages\altair\vegalite\v4\api.py in to_dict(self, *args, **kwargs)

c:\Users\usuario\AppData\Local\Programs\Python\Python311\Lib\site-packages\altair\vegalite\v4\api.py in to_dict(self, *args, **kwargs)

c:\Users\usuario\AppData\Local\Programs\Python\Python311\Lib\site-packages\altair\vegalite\v4\api.py in _prepare_data(data, context)

c:\Users\usuario\AppData\Local\Programs\Python\Python311\Lib\site-packages\toolz\functoolz.py in pipe(data, *funcs)
626 """
627 for func in funcs:
--> 628 data = func(data)
629 return data
630

c:\Users\usuario\AppData\Local\Programs\Python\Python311\Lib\site-packages\toolz\functoolz.py in call(self, *args, **kwargs)
302 def call(self, *args, **kwargs):
303 try:
--> 304 return self._partial(*args, **kwargs)
305 except TypeError as exc:
306 if self._should_curry(args, kwargs, exc):

c:\Users\usuario\AppData\Local\Programs\Python\Python311\Lib\site-packages\altair\vegalite\data.py in default_data_transformer(data, max_rows)
17
18
...
-> 5989 Number of items from axis to return. Cannot be used with frac.
5990 Default = 1 if frac = None.
5991 frac : float, optional

AttributeError: 'Series' object has no attribute 'iteritems'

It seems that Altair is still trying to use 'iteritems' with pandas.
I am with the latest version of both.

@joelostblom
Copy link
Contributor

Looking at the path in your error message, it seems like you're still using Altair v4. Make sure you close down all notebooks and restart your IDE after updating to Altair 5, and try again after that.

@mbbau
Copy link

mbbau commented Jan 29, 2024

Thank you very much for this! I did not know I was using Altair v4! It worked when restarted the IDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants