docstr: Utility function to get df label by finding the nearest assignment.
  
  Sort assignment nodes list (copy of the list) by line number.
  Iterate over the assignment nodes list. If the assignment node's value
  looks like `dfs[<index>]` and target label equals to `target_name`,
  set `nearest_assignment` to "dfs[<index>]".
  
  Args:
      current_lineno (int): Number of the current processed line.
      assignments (list[ast.Assign]): List of assignment nodes.
      target_name (str): Name of the target variable. The assignment
          node is supposed to assign to this name.
  
  Returns:
      str: The string representing df label, looks like "dfs[<index>]".
docstr_tok: ["Utility","function","to","get","df","label","by","finding","the","nearest","assignment",".","Sort","assignment","nodes","list","(","copy","of","the","list",")","by","line","number",".","Iterate","over","the","assignment","nodes","list",".","If","the","assignment","node","'s","value","looks","like","`","dfs","[","<","index",">","]","`","and","target","label","equals","to","`","target_name","`",",","set","`","nearest_assignment","`","to","``","dfs","[","<","index",">","]","''",".","Args",":","current_lineno","(","int",")",":","Number","of","the","current","processed","line",".","assignments","(","list","[","ast.Assign","]",")",":","List","of","assignment","nodes",".","target_name","(","str",")",":","Name","of","the","target","variable",".","The","assignment","node","is","supposed","to","assign","to","this","name",".","Returns",":","str",":","The","string","representing","df","label",",","looks","like","``","dfs","[","<","index",">","]","''","."]
code: def _get_df_id_by_nearest_assignment(
      current_lineno: int,
      assignments: list[ast.Assign],
      target_name: str,
  ):
      """
      Utility function to get df label by finding the nearest assignment.
  
      Sort assignment nodes list (copy of the list) by line number.
      Iterate over the assignment nodes list. If the assignment node's value
      looks like `dfs[<index>]` and target label equals to `target_name`,
      set `nearest_assignment` to "dfs[<index>]".
  
      Args:
          current_lineno (int): Number of the current processed line.
          assignments (list[ast.Assign]): List of assignment nodes.
          target_name (str): Name of the target variable. The assignment
              node is supposed to assign to this name.
  
      Returns:
          str: The string representing df label, looks like "dfs[<index>]".
      """
      nearest_assignment = None
      assignments = sorted(assignments, key=lambda node: node.lineno)
      for assignment in assignments:
          if assignment.lineno > current_lineno:
              return nearest_assignment
          try:
              is_subscript = isinstance(assignment.value, ast.Subscript)
              dfs_on_the_right = assignment.value.value.id == "dfs"
              assign_to_target = assignment.targets[0].id == target_name
              if is_subscript and dfs_on_the_right and assign_to_target:
                  nearest_assignment = (
                      f"dfs[{assignment.value.slice.value}]"
                  )
          except AttributeError:
              continue
  
imports: import re
  import ast
  import uuid
  from collections import defaultdict
  import astor
  import pandas
  from pandasai.helpers.path import find_project_root
  from pandasai.helpers.skills_manager import SkillsManager
  from pandasai.helpers.sql import extract_table_names
  from .node_visitors import AssignmentVisitor, CallVisitor
  from .save_chart import add_save_chart
  from .optional import import_dependency
  from ..exceptions import BadImportError, MaliciousQueryError, NoResultFoundError, InvalidConfigError
  from ..constants import WHITELISTED_BUILTINS, WHITELISTED_LIBRARIES
  from typing import Union, List, Generator, Any
  from ..helpers.logger import Logger
  from ..schemas.df_config import Config
  import logging
  import traceback
label_desc: Use image node_id 18 for calling the CodeManager obj's underlying member method code with example usage: obj._get_df_id_by_nearest_assignment(current_lineno, assignments, target_name) and returns: nearest_assignment