Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

The `Cursor.fetch_dataframe` method doesn't respect case-sensitivity

Abierto
#238 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
50/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
postgresql, python
Área
databases

Línea de trabajo

Comienza en redshift_connector/cursor.py, en la implementación de fetch_dataframe alrededor de la línea 526, donde los nombres de las columnas se convierten a minúsculas. Reproduce el problema con enable_case_sensitive_identifier establecido en true y una consulta que devuelva tanto "C" como "c". Se considera terminado cuando el DataFrame resultante conserva los nombres de las columnas devueltos por Redshift, incluida la distinción entre mayúsculas y minúsculas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Driver version

2.1.3

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.76169

Client Operating System

macos

Python version

3.12.6

Problem description

The Cursor.fetch_dataframe method always lowercases column names, irrespective of the case-sensitivity configuration value. This behavior is unexpected, because the resulting DataFrame's columns may be treated as case-insensitive, even when that flag is set to true.

One example where this can be problematic is demonstrated below:

from redshift_connector import connect

conn = connect(<connection options>)
cursor = conn.cursor()

cursor.execute('SET enable_case_sensitive_identifier TO true')
cursor.execute('WITH t AS (SELECT 1 AS "C", 2 AS "c") SELECT * FROM t')

# cursor.fetch_dataframe()
#    c  c
# 0  1  2

# cursor.fetch_dataframe().to_dict()
# <stdin>:1: UserWarning: DataFrame columns are not unique, some columns will be omitted.
# {'c': {0: 2}}

Possible solutions

I see that there is an open PR related to this issue, but I don't think it solves it. I believe that the correct way to solve this is to get rid of the lower() call in line 526 altogether. That would mean that the columns produced by the driver reflect those returned by Redshift, hence respecting the case-sensitivity configuration value (see image below). I plan to open a PR with this fix soon.

Screenshot 2024-10-18 at 12 29 24 AM

P.S.: I see that the line of interest was introduced in the first commit of this repo (!) and hasn't changed since. My hunch is that this was most likely an oversight, since Redshift's documentation at the date of that commit had no mention of the enable_case_sensitive_identifier flag, so the driver must've not been updated to take it into account after it was introduced.

Lenguaje dominante
Python
Estrellas
220
Forks
86
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws/amazon-redshift-python-driver

Todos los issues de aws/amazon-redshift-python-driver

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.