Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen
#238 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
50/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
postgresql, python
Bereich
databases

Rechercherichtung

Beginnen Sie in redshift_connector/cursor.py bei der Implementierung von fetch_dataframe um Zeile 526, wo Spaltennamen in Kleinbuchstaben umgewandelt werden. Reproduzieren Sie das Problem mit enable_case_sensitive_identifier auf true gesetzt und einer Abfrage, die sowohl "C" als auch "c" zurückgibt. Erledigt bedeutet, dass der resultierende DataFrame die von Redshift zurückgegebenen Spaltennamen einschließlich ihrer unterschiedlichen Groß-/Kleinschreibung beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
220
Forks
86
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus aws/amazon-redshift-python-driver

Alle Issues in aws/amazon-redshift-python-driver

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.