Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-5-sonnet-20241022· AnthropicHugging Face LMArena Human Preference 140K

TypeError: int() argument must be a string, a bytes-like object or a real number, not…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    TypeError: int() argument must be a string, a bytes-like object or a real number, not 'Expr'

    def add_features(df): df_clone = df.clone() df_clone = df_clone.with_columns([

        # Разница в трофеях
        (pl.col("player_1_trophies") - pl.col("player_2_trophies")).alias("trophy_diff"),
        
        # Среднее арифметическое трофеев
        ((pl.col("player_1_trophies") + pl.col("player_2_trophies")) / 2).alias("avg_trophies"),
        
        # Первый игрок имеет больше корон хотя бы на 30
        int((pl.col("player_1_trophies") - pl.col("player_2_trophies")) >= 30).alias("is_first_better"),
    
    
        # Второй игрок имеет больше корон хотя бы на 30
        int((pl.col("player_2_trophies") - pl.col("player_1_trophies")) >= 30).alias("is_second_better")
    
    ])
    return df_clone
    
  2. Claude Assistant

    The error occurs because you're trying to convert a Polars expression directly to an integer using int(). In Polars, you need to use the .cast() method to convert expressions to different types.

    Here's the corrected version of your code:

    def add_features(df): 
        df_clone = df.clone()
        df_clone = df_clone.with_columns([
            
            # Разница в трофеях
            (pl.col("player_1_trophies") - pl.col("player_2_trophies")).alias("trophy_diff"),
            
            # Среднее арифметическое трофеев
            ((pl.col("player_1_trophies") + pl.col("player_2_trophies")) / 2).alias("avg_trophies"),
            
            # Первый игрок имеет больше корон хотя бы на 30
            ((pl.col("player_1_trophies") - pl.col("player_2_trophies")) >= 30).cast(pl.Int32).alias("is_first_better"),
    
            # Второй игрок имеет больше корон хотя бы на 30
            ((pl.col("player_2_trophies") - pl.col("player_1_trophies")) >= 30).cast(pl.Int32).alias("is_second_better")
    
        ])
        return df_clone
    

    The key changes are:

    1. Replaced int() with .cast(pl.Int32)
    2. The boolean comparison will now be properly converted to 0s and 1s

    This should resolve the TypeError you're encountering. The .cast(pl.Int32) method properly converts the boolean expression to integers within the Polars framework.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.