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: bump deps, fix issues with row rendering #136

Merged
merged 2 commits into from
Dec 19, 2024
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- Drops support for Python 3.8
- Adds support for Python 3.13

## [0.10.0] - 2024-10-31

- Adds an optional parameter to DataTable to disable rendering of string data as Rich Markup.
Expand Down
1,870 changes: 1,040 additions & 830 deletions poetry.lock

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@ build-backend = "poetry.core.masonry.api"


[tool.poetry.dependencies]
python = "^3.8"
textual = ">=0.41.0"
pyarrow = ">=7.0.0"
python = ">=3.9,<3.14"
textual = ">=0.89.1"
pyarrow = ">=16.1.0"
polars = { version = ">=0.20.0", optional = true }
pytz = {version = ">=2023,<2025", python = "<3.9.0"} # arrow timestamptz support py<3.9
tzdata = {version = ">=2023", markers = "sys_platform == 'win32'"} # arrow timestamptz support on windows
tzdata = { version = ">=2023", markers = "sys_platform == 'win32'" } # arrow timestamptz support on windows

[tool.poetry.extras]
polars = ["polars"]

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.3.1"
textual-dev = "^1.0.1"
pandas = { version="^2.1.1", python=">=3.9,<3.13" }
numpy = { version="^1", python=">=3.9,<3.13" }
pyinstrument = "^4.6.0"
pandas = "^2.1.1"
numpy = "^1"
pyinstrument = "^5"

[tool.poetry.group.static.dependencies]
ruff = "^0.5"
mypy = "^1.10.0"
pandas-stubs = { version="^2.1.1", python=">=3.9,<3.13" }
pandas-stubs = "^2.1.1"

[tool.poetry.group.test.dependencies]
pytest = "^7.3.1"
Expand All @@ -45,13 +44,13 @@ polars = ">=0.20.0"


[tool.ruff]
target-version = "py38"
target-version = "py39"

[tool.ruff.lint]
select = ["A", "B", "E", "F", "I"]

[tool.mypy]
python_version = "3.8"
python_version = "3.9"
files = [
"src/**/*.py",
"tests/unit_tests/**/*.py"
Expand Down
6 changes: 3 additions & 3 deletions src/textual_fastdatatable/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


class TableApp(App, inherit_bindings=False):
BINDINGS = [("ctrl+q", "quit", "Quit")]
BINDINGS = [("ctrl+q", "quit", "Quit"), ("ctrl+d", "quit", "Quit")]

def compose(self) -> ComposeResult:
backend = ArrowBackend.from_parquet("./tests/data/lap_times_100000.parquet")
yield DataTable(backend=backend, cursor_type="range")
backend = ArrowBackend.from_parquet("./tests/data/wide_100000.parquet")
yield DataTable(backend=backend, cursor_type="range", fixed_columns=2)


if __name__ == "__main__":
Expand Down
25 changes: 14 additions & 11 deletions src/textual_fastdatatable/data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,7 @@ def _render_line_in_row(
cursor_location: Coordinate,
hover_location: Coordinate,
selection_anchor_location: Coordinate | None,
) -> tuple[SegmentLines, SegmentLines, int]:
) -> tuple[SegmentLines, SegmentLines, int, int]:
"""Render a single line from a row in the DataTable.

Args:
Expand Down Expand Up @@ -2023,15 +2023,16 @@ def _render_line_in_row(
col_widths = [
col.render_width for col in self.ordered_columns[self.fixed_columns :]
]
cumulative_width = fixed_width
cumulative_width = 0
hidden_width = 0
visible_width = self.size.width - fixed_width
col1 = self.fixed_columns
offset = x1 - cumulative_width
col2 = None
for i, w in enumerate(col_widths, start=self.fixed_columns):
if cumulative_width <= x1:
if cumulative_width < x1:
col1 = i
offset = x1 - cumulative_width
if col2 is None and cumulative_width + w >= x2:
hidden_width = cumulative_width
if col2 is None and cumulative_width - x1 > visible_width:
col2 = i
break
cumulative_width += w
Expand All @@ -2056,7 +2057,7 @@ def _render_line_in_row(

if cache_key in self._row_render_cache:
cache_contents = self._row_render_cache[cache_key]
return cache_contents[0], cache_contents[1], offset
return cache_contents[0], cache_contents[1], hidden_width, fixed_width

should_highlight = self._should_highlight
should_highlight_range = self._should_highlight_range
Expand Down Expand Up @@ -2145,7 +2146,7 @@ def _render_line_in_row(
)
remaining_space = max(0, widget_width - table_width)
background_color = self.background_colors[1]
faded_color = Color.from_rich_color(row_style.bgcolor).blend( # type: ignore
faded_color = Color.from_rich_color(row_style.bgcolor).blend(
background_color, factor=0.25
)
faded_style = Style.from_color(
Expand All @@ -2154,7 +2155,7 @@ def _render_line_in_row(
scrollable_row.append([Segment(" " * remaining_space, faded_style)])

self._row_render_cache[cache_key] = (fixed_row, scrollable_row)
return (fixed_row, scrollable_row, offset)
return (fixed_row, scrollable_row, hidden_width, fixed_width)

def _get_offsets(self, y: int) -> tuple[int, int]:
"""Get row key and line offset for a given line.
Expand Down Expand Up @@ -2219,7 +2220,7 @@ def _render_line(self, y: int, x1: int, x2: int, base_style: Style) -> Strip:
if cache_key in self._line_cache:
return self._line_cache[cache_key]

fixed, scrollable, xoffset = self._render_line_in_row(
fixed, scrollable, hidden_width, fixed_width = self._render_line_in_row(
row_index,
0,
x1,
Expand All @@ -2233,7 +2234,9 @@ def _render_line(self, y: int, x1: int, x2: int, base_style: Style) -> Strip:
fixed_line: list[Segment] = list(chain.from_iterable(fixed)) if fixed else []
scrollable_line: list[Segment] = list(chain.from_iterable(scrollable))

segments = fixed_line + line_crop(scrollable_line, xoffset, x2, width)
segments = fixed_line + line_crop(
scrollable_line, x1 - hidden_width, x2 - hidden_width, width - fixed_width
)
strip = Strip(segments).adjust_cell_length(width, base_style).simplify()

self._line_cache[cache_key] = strip
Expand Down
2,187 changes: 1,095 additions & 1,092 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Large diffs are not rendered by default.

Loading