Skip to content
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
4 changes: 3 additions & 1 deletion python/cudf/cudf/pandas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def profile(function_profile, line_profile, fn):
raise RuntimeError("Enabling the profiler requires a script name.")
if line_profile:
with open(fn) as f:
lines = f.readlines()
# lines_with_profiling joins the lines with "\n", so they must not
# keep their own line endings (the cell magic splits on "\n" too).
lines = f.read().split("\n")

with tempfile.NamedTemporaryFile(mode="w+b", suffix=".py") as f:
f.write(lines_with_profiling(lines, function_profile).encode())
Expand Down
11 changes: 11 additions & 0 deletions python/cudf/cudf_pandas_tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import re
import subprocess
import tempfile
import textwrap
Expand Down Expand Up @@ -59,6 +60,16 @@ def test_run_cudf_pandas_line_profile_preserves_file(tmp_path):
assert str(script) in res


def test_run_cudf_pandas_line_profile_reports_script_line_numbers(tmp_path):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
# ``--line-profile`` must report the line numbers of the original script.
script = tmp_path / "script.py"
script.write_text("x = 1\ny = 2\nz = 3\nprint(x + y + z)\n")

res = _run_python(cudf_pandas=True, command=f"--line-profile {script}")
reported = re.findall(r"^[│|]\s*(\d+)\s*[│|]", res, re.MULTILINE)
assert reported == ["1", "2", "3", "4"]


def test_run_cudf_pandas_with_script_with_cmd_args():
input_args_and_code = """-c 'import pandas as pd; df = pd.DataFrame({"a": [1, 2, 3]}); print(df["a"].sum())'"""

Expand Down
Loading