The `Cursor.fetch_dataframe` method doesn't respect case-sensitivity
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 50/100
Direção de pesquisa
Comece em redshift_connector/cursor.py, na implementação de fetch_dataframe por volta da linha 526, onde os nomes das colunas são convertidos para minúsculas. Reproduza o problema com enable_case_sensitive_identifier definido como true e a consulta retornando tanto "C" quanto "c". Considera-se concluído quando o DataFrame resultante preserva os nomes das colunas retornados pelo Redshift, incluindo a distinção entre maiúsculas e minúsculas.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
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.
- Linguagem predominante
- Python
- Estrelas
- 220
- Forks
- 89
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de aws/amazon-redshift-python-driver
-
docs: client_protocol_version missing from Connection Parameters tableTalvez já em andamento @reginaldalfret assumiu há 9 dias. Aberta
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 74/100
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 30/100
aws/amazon-redshift-python-driver#268 · 2 reações ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
aws/amazon-redshift-python-driver#265 · 1 comentário · 4 reações ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 45/100
Todas as issues de aws/amazon-redshift-python-driver
Issues semelhantes
-
comp/gateway comp/plugins duplicate P3 type/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
NousResearch/hermes-agent#137019 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
bot-triaged module: docs triaged
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
new-entry
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
BinWang28/audio-ai-hub#194 ·
-
confluence: a paged listing's links re-encode a parameter they carry, where real carries it as sentAbertafidelity
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 63/100
Mantenedores costumam responder em até 1 dia