1

I have configured the database connection and sql query in a pandas read sql query function, but when the function is running its throwing an error.

def fetchDbTable(candidate_id):
    start_time = time.time()
    # candidate_id = 793
    schema = env_config.get("DEV_DB_SCHEMA_PUBLIC")

    # Create Db engine
    engine = createEngine(
        user=env_config.get("DEV_DB_USER"),
        pwd=env_config.get("DEV_DB_PASSWORD"),
        host=env_config.get("DEV_DB_HOST"),
        db=env_config.get("DEV_DB_NAME"),
    )


    # Create query for resume
    query_resume = (
        """
        select
        a.*,
        b.*,
        c.*

        from
        """
        + schema
        + """.resume_intl_candidate_info a,
        """
        + schema
        + """.resume_intl_candidate_resume b,
        """
        + schema
        + """.resume_intl_candidate_work_experience c

        where
        a.c_id = b.c_id_fk_id
        --and a.c_id = c.c_id_fk_id
        and b.r_id = c.r_id_fk_id
        and b.active_flag = 't'
        and a.c_id = """
        + str(candidate_id)
    )

    # Fetch database
    df_resume = pd.read_sql_query(query_resume, con=engine)

pandas current version- 1.5.2, numpy current version-1.23.5 in local

but the version used in the server is pandas - 0.23.0, numpy = 1.16.5

I need to change the code for the latest version and run it without an error.

Can you please help me fix the issue I had spent more than 2 days and i couldn't able to come to a solution.

Error throwing as:

Traceback (most recent call last):
  File "/home/vinoth/Documents/Req_Intelligence-master/Req_Intelligence-master/req_intl/resume_intl/extractedfields.py", line 483, in save_create_document
    meta_df = fetchDbTable(candidate_info.c_id)
  File "/home/vinoth/Documents/Req_Intelligence-master/Req_Intelligence-master/req_intl/resume_intl/candidate_meta_info.py", line 132, in fetchDbTable
    df_resume = pd.read_sql_query(query_resume, con=engine)
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/io/sql.py", line 397, in read_sql_query
    return pandas_sql.read_query(
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/io/sql.py", line 1575, in read_query
    frame = _wrap_result(
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/io/sql.py", line 151, in _wrap_result
    frame = _parse_date_columns(frame, parse_dates)
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/io/sql.py", line 126, in _parse_date_columns
    for col_name, df_col in data_frame.items():
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/core/frame.py", line 1325, in items
    yield k, self._ixs(i, axis=1)
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/core/frame.py", line 3728, in _ixs
    col_mgr = self._mgr.iget(i)
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 1136, in iget
    values = block.iget(self.blklocs[i])
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/core/internals/blocks.py", line 834, in iget
    return self.values[i]  # type: ignore[index]
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py", line 358, in __getitem__
    "Union[DatetimeLikeArrayT, DTScalarOrNaT]", super().__getitem__(key)
  File "/home/vinoth/.local/lib/python3.10/site-packages/pandas/core/arrays/_mixins.py", line 289, in __getitem__
    result = self._ndarray[key]
IndexError: index 1 is out of bounds for axis 0 with size 1

vinoth kumar
  • 101
  • 2
  • 11

0 Answers0