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

'functools.partial' object has no attribute '__code__' in Jupyter Notebooks #210

Closed
2 tasks done
Meehai opened this issue Nov 17, 2022 · 2 comments
Closed
2 tasks done

Comments

@Meehai
Copy link

Meehai commented Nov 17, 2022

General

  • Operating System: Ubuntu 20.04
  • Python version: 3.9.13
  • Pandas version: 1.4.4
  • Pandarallel version: 1.6.3

Acknowledgement

  • My issue is NOT present when using pandas without alone (without pandarallel)
  • If I am on Windows, I read the Troubleshooting page
    before writing a new bug report

Bug description

functool.partial cannot be used in junction with jupyter notebooks and pandarallel

Observed behavior

Write here the observed behavior

Expected behavior

Write here the expected behavior

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

import pandas as pd
from functools import partial
from typing import List
import numpy as np
from pandarallel import pandarallel

pandarallel.initialize(progress_bar=True)

def processing_fn(row: pd.Series, invalid_numbers: List[int], default: int) -> pd.Series:
    cond = row.isin(invalid_numbers)
    row[cond] = default
    return row

data = pd.DataFrame(np.random.randint(low=-10, high=10, size=(10000, 5)))
print("Before", (data.values == 100).sum())

fn = partial(processing_fn, invalid_numbers=[-5, 2, 5], default=100)
new_data = data.apply(fn, axis=1)

print("After serial", (new_data.values == 100).sum())

data = data.parallel_apply(fn, axis=1)
print("After parallel", (data.values == 100).sum())

Works fine in a standalone script, but fails if ran in Jupyter notebook

@till-m
Copy link
Collaborator

till-m commented Feb 3, 2023

Hey, sorry for the delay. The script runs without issue for me, both inside jupyter notebooks and outside.

@Meehai
Copy link
Author

Meehai commented Feb 3, 2023

Yeah, you are right, it seems to work now both on a local env and on some remote server. Perhaps it was a different issue that triggered this that I was not aware of.

I guess you can close it and I can submit a new one if I ever encounter it again.

@till-m till-m closed this as completed Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants