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 Found - Return Lists Directly vs. Pandas Series #7377

Closed
richardags opened this issue May 23, 2024 · 3 comments
Closed

Bug Found - Return Lists Directly vs. Pandas Series #7377

richardags opened this issue May 23, 2024 · 3 comments
Labels
bug status:Needs Info status:Needs Triage Applied to issues that need triage

Comments

@richardags
Copy link

richardags commented May 23, 2024

Detailed report in my repository, please follow the link before comment:

https://github.com/richardags/JupyterNotebookBugReport/blob/main/bug.ipynb

@richardags richardags added bug status:Needs Triage Applied to issues that need triage labels May 23, 2024
@RRosio
Copy link
Collaborator

RRosio commented May 28, 2024

Hi @richardags, thank you for opening this issue. Is this an issue you see only when running your code in Notebook, or do you also experience this issue when running your code as a Python script? This could help identify whether this is an issue in Notebook or elsewhere.

@richardags
Copy link
Author

richardags commented Jun 4, 2024

Hi @richardags, thank you for opening this issue. Is this an issue you see only when running your code in Notebook, or do you also experience this issue when running your code as a Python script? This could help identify whether this is an issue in Notebook or elsewhere.

I test it as you mentioned, it has the same results using python terminal to run the code directly:

1. Without importing pandas

C:\Users{user}\Downloads>python without_pandas.py

user_artists_name = [
    "Radiohead", "Pink Floyd", "Opeth", "System of a Down", "Arcade Fire",
    "L'Arc~en~Ciel", "Pearl Jam", "Metallica", "Dream Theater", "Symphony X",
    "Testament", "Queen", "The Mars Volta", "Ayreon", "Incubus",
    "Faith No More", "Queensrÿche", "Kansas", "Elio e le Storie Tese",
    "Spock's Beard", "Shadow Gallery", "Pain of Salvation", "Amorphis", "Toto",
    "Litfiba", "Fates Warning", "Riverside", "Orphaned Land", "Adagio",
    "Andromeda", "Green Carnation", "Premiata Forneria Marconi", "Marty Friedman",
    "Gordian Knot", "Zucchero", "A.C.T", "Giovanni Allevi", "Act",
    "Wolverine", "Allen-Lande", "Pin-Up Went Down", "regsgnep", "Pathosray",
    "Quintorigo", "Frost", "rEarth", "Timoria", "Fabio Concato",
    "Pallas", "Quella Mezza Sporca Dozzina"
]

artists_name_array = [
    [
        "Porcupine Tree", "Radiohead", "Pink Floyd", "Paradise Lost", "Blackfield",
        "Opeth", "Muse", "Queens of the Stone Age", "The Beatles", "Massive Attack",
        "Katatonia", "The Smashing Pumpkins", "Anathema", "Trans-Siberian Orchestra",
        "Alice in Chains", "Soundgarden", "Afghan Whigs", "Dream Theater", "Yanni",
        "Ayreon", "Tool", "Agalloch", "Daddy Yankee", "King Diamond", "Spock's Beard",
        "Pain of Salvation", "Frank Zappa", "dredg", "Devin Townsend Project", "Marillion",
        "Ulver", "Cynic", "Septic Flesh", "Riverside", "Orphaned Land", "Nightingale",
        "Phideaux", "Café Tacuba", "Premiata Forneria Marconi", "Dog Fashion Disco",
        "maudlin of the Well", "Juan Luis Guerra", "Edge of Sanity", "岩代太郎",
        "The Gourishankar", "Sigh", "Place Vendome", "이박사", "Subterranean Masquerade",
        "Moon Safari"
    ]
]

def get_artists_name_array(user_id):
    return artists_name_array

def get_artists_name_by_user_id(user_id):
    return user_artists_name

def get_recommendations(user_id, artists_limit):
    artists_name_array = get_artists_name_array(user_id)
    user_artists_name = get_artists_name_by_user_id(user_id)  # Using a set for faster lookups
    recommendations = []
    
    for artists_name in artists_name_array:
        for artist_name in artists_name:
            if artist_name not in user_artists_name and artist_name not in recommendations:
                recommendations.append(artist_name)
                if len(recommendations) >= artists_limit:
                    return recommendations
    
    return recommendations

# Test call
recommendations = get_recommendations(user_id=1, artists_limit=5)
print(recommendations)

OUTPUT:

['Porcupine Tree', 'Paradise Lost', 'Blackfield', 'Muse', 'Queens of the Stone Age']

2. Importing Pandas

C:\Users{user}\Downloads>python with_pandas.py

import pandas as pd

user_artists_name = [
    "Radiohead", "Pink Floyd", "Opeth", "System of a Down", "Arcade Fire",
    "L'Arc~en~Ciel", "Pearl Jam", "Metallica", "Dream Theater", "Symphony X",
    "Testament", "Queen", "The Mars Volta", "Ayreon", "Incubus",
    "Faith No More", "Queensrÿche", "Kansas", "Elio e le Storie Tese",
    "Spock's Beard", "Shadow Gallery", "Pain of Salvation", "Amorphis", "Toto",
    "Litfiba", "Fates Warning", "Riverside", "Orphaned Land", "Adagio",
    "Andromeda", "Green Carnation", "Premiata Forneria Marconi", "Marty Friedman",
    "Gordian Knot", "Zucchero", "A.C.T", "Giovanni Allevi", "Act",
    "Wolverine", "Allen-Lande", "Pin-Up Went Down", "regsgnep", "Pathosray",
    "Quintorigo", "Frost", "rEarth", "Timoria", "Fabio Concato",
    "Pallas", "Quella Mezza Sporca Dozzina"
]

artists_name_array = [
    [
        "Porcupine Tree", "Radiohead", "Pink Floyd", "Paradise Lost", "Blackfield",
        "Opeth", "Muse", "Queens of the Stone Age", "The Beatles", "Massive Attack",
        "Katatonia", "The Smashing Pumpkins", "Anathema", "Trans-Siberian Orchestra",
        "Alice in Chains", "Soundgarden", "Afghan Whigs", "Dream Theater", "Yanni",
        "Ayreon", "Tool", "Agalloch", "Daddy Yankee", "King Diamond", "Spock's Beard",
        "Pain of Salvation", "Frank Zappa", "dredg", "Devin Townsend Project", "Marillion",
        "Ulver", "Cynic", "Septic Flesh", "Riverside", "Orphaned Land", "Nightingale",
        "Phideaux", "Café Tacuba", "Premiata Forneria Marconi", "Dog Fashion Disco",
        "maudlin of the Well", "Juan Luis Guerra", "Edge of Sanity", "岩代太郎",
        "The Gourishankar", "Sigh", "Place Vendome", "이박사", "Subterranean Masquerade",
        "Moon Safari"
    ]
]

def get_artists_name_array(user_id):
    return pd.Series(artists_name_array)

def get_artists_name_by_user_id(user_id):
    return pd.Series(user_artists_name)

def get_recommendations(user_id, artists_limit):
    artists_name_array = get_artists_name_array(user_id)
    user_artists_name = get_artists_name_by_user_id(user_id)  # Using a set for faster lookups
    recommendations = []
    
    for artists_name in artists_name_array:
        for artist_name in artists_name:
            if artist_name not in user_artists_name and artist_name not in recommendations:
                recommendations.append(artist_name)
                if len(recommendations) >= artists_limit:
                    return recommendations
    
    return recommendations

# Test call
recommendations = get_recommendations(user_id=1, artists_limit=5)
print(recommendations)

OUTPUT:

['Porcupine Tree', 'Radiohead', 'Pink Floyd', 'Paradise Lost', 'Blackfield']

@RRosio
Copy link
Collaborator

RRosio commented Jun 4, 2024

Thank you for the follow-up information @richardags! As this issue can be replicated separately from Notebook, it would seem that it is not an issue that originates from Notebook, I will go ahead and close this issue here. I would recommend looking at the Pandas repository, in case an issue has been opened there, or needs to be opened. Please feel free to open any additional issues!

@RRosio RRosio closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status:Needs Info status:Needs Triage Applied to issues that need triage
Projects
None yet
Development

No branches or pull requests

2 participants