Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cursor, fetch_dataframe): use column names in cursor's description as is #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redshift_connector/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def fetch_dataframe(self: "Cursor", num: typing.Optional[int] = None) -> "pandas

columns: typing.Optional[typing.List[typing.Union[str, bytes]]] = None
try:
columns = [column[0].lower() for column in self.description]
columns = [column[0] for column in self.description]
except:
warn("No row description was found. pandas dataframe will be missing column labels.", stacklevel=2)

Expand Down
17 changes: 17 additions & 0 deletions test/unit/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ def test_fetch_dataframe_no_results(mocker) -> None:
assert mock_cursor.fetch_dataframe(1).size == 0


@pandas_only
def test_fetch_dataframe_respects_case_sensitivity(mocker) -> None:
import pandas as pd

mock_cursor: Cursor = Cursor.__new__(Cursor)
mocker.patch(
"redshift_connector.Cursor._getDescription",
return_value=[("C", 23, None, None, None, None, None)],
)
mocker.patch("redshift_connector.Cursor.__next__", side_effect=StopIteration("mocked end"))

df = mock_cursor.fetch_dataframe()

assert df.size == 0
assert df.columns.to_list() == ["C"]


def test_raw_connection_property_warns() -> None:
mock_cursor: Cursor = Cursor.__new__(Cursor)
mock_cursor._c = Connection.__new__(Connection)
Expand Down