Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Fix select slice with [:] #196

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions greenplumpython/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html>`_ for syncing updates.
"""
import json
import sys
from collections import abc
from functools import partialmethod, singledispatchmethod
from typing import (
Expand Down Expand Up @@ -110,12 +111,14 @@ def _(self, rows: slice) -> "DataFrame":
raise NotImplementedError()
offset_clause = "" if rows.start is None else f"OFFSET {rows.start}"
limit_clause = (
""
sys.maxsize
if rows.stop is None
else f"LIMIT {rows.stop if rows.start is None else rows.stop - rows.start}"
else rows.stop
if rows.start is None
else rows.stop - rows.start
)
return DataFrame(
f"SELECT * FROM {self._name} {limit_clause} {offset_clause}",
f"SELECT * FROM {self._name} LIMIT {limit_clause} {offset_clause}",
parents=[self],
)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def test_dataframe_getitem_slice_off_limit(db: gp.Database, t: gp.DataFrame):
assert len(list(t[2:5])) == 3


def test_dataframe_getitem_slice_off_limit(db: gp.Database, t: gp.DataFrame):
query = t[:]._build_full_query()
assert len(list(t[:])) == 10
assert query.__contains__("LIMIT")


def test_dataframe_display_repr(db: gp.Database):
# fmt: off
rows = [(1, 1, "Lion",), (2, 2, "Tiger",), (3, 3, "Wolf",), (4, 4, "Fox")]
Expand Down