question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: 'generator' object is not subscriptable error in colab - works in VScode

See original GitHub issue

General

  • Operating System: OSX
  • Python version: 3.7.13
  • Pandas version: 1.3.5
  • Pandarallel version: 1.6.2

Acknowledgement

  • Issue happens on Colab only. When I use VScode, the problem does not happen

Bug description

I get the error:

100.00%
1 / 1
100.00%
1 / 1
100.00%
1 / 1
100.00%
1 / 1
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-16-b9ca1a6007f2>](https://localhost:8080/#) in <module>()
      1 data = {'Name': ['Tom', 'Joseph', 'Krish', 'John'], 'Age': [20, 21, 19, 18]}
      2 df = pd.DataFrame(data)
----> 3 df['HalfAge'] = df.parallel_apply(lambda r: r.Age/2,axis=1)

2 frames
[/usr/local/lib/python3.7/dist-packages/pandarallel/core.py](https://localhost:8080/#) in closure(data, user_defined_function, *user_defined_function_args, **user_defined_function_kwargs)
    324             return wrapped_reduce_function(
    325                 (Path(output_file.name) for output_file in output_files),
--> 326                 reduce_extra,
    327             )
    328 

[/usr/local/lib/python3.7/dist-packages/pandarallel/core.py](https://localhost:8080/#) in closure(output_file_paths, extra)
    197         )
    198 
--> 199         return reduce_function(dfs, extra)
    200 
    201     return closure

[/usr/local/lib/python3.7/dist-packages/pandarallel/data_types/dataframe.py](https://localhost:8080/#) in reduce(datas, extra)
     45             datas: Iterable[pd.DataFrame], extra: Dict[str, Any]
     46         ) -> pd.DataFrame:
---> 47             axis = 0 if isinstance(datas[0], pd.Series) else 1 - extra["axis"]
     48             return pd.concat(datas, copy=False, axis=axis)
     49 

TypeError: 'generator' object is not subscriptable

Minimal but working code sample to ease bug fix for pandarallel team

!pip install pandarallel
from pandarallel import pandarallel
pandarallel.initialize(progress_bar=True)

import pandas as pd

data = {'Name': ['Tom', 'Joseph', 'Krish', 'John'], 'Age': [20, 21, 19, 18]}
df = pd.DataFrame(data)
df['HalfAge'] = df.parallel_apply(lambda r: r.Age/2,axis=1)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
till-mcommented, Aug 4, 2022

Hi all,

I think I introduced this bug in a recent PR. I assume rolling back to pandarallel 1.6.1 (i.e. !pip install pandarallel==1.6.1) should work as a temporary fix while I have a look at the issue.

Very sorry about the bug, I tested on regular jupyter notebooks but not in Colab.

2reactions
glassonion1commented, Aug 4, 2022

I have same error occured in google colab.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"'generator' object is not subscriptable" error - Stack Overflow
Your x value is is a generator object, which is an Iterator : it generates values in order, as they are requested by...
Read more >
Python TypeError: 'type' object is not subscriptable Solution
The “TypeError: 'type' object is not subscriptable” error is raised when you try to access an object using indexing whose data type is...
Read more >
PYTHON : "'generator' object is not subscriptable" error
PYTHON : "' generator ' object is not subscriptable " error [ Gift : Animated Search Engine : https://www.hows.tech/p/recommended.html ] PYTHON ...
Read more >
TypeError: 'generator' object is not subscriptable for ... - GitHub
I am trying to run the example given in the readme and getting an error: Please help. Output and Error stack:
Read more >
datetime object is not subscriptable - You.com | The AI Search ...
Either your trans or your item values are datetime.time object's - thats what the error tells you: TypeError: 'datetime.time' object is not subscriptable....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found