Skip to content

Commit

Permalink
Fix a typo and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Nov 28, 2023
1 parent 823d321 commit b18c45c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/pandas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def profile(function_profile, line_profile, fn):
elif function_profile:
with Profiler() as profiler:
yield fn
profiler.print_per_func_stats()
profiler.print_per_function_stats()
else:
yield fn

Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf_pandas_tests/data/profile_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, NVIDIA CORPORATION.

import pandas as pd

URL = "https://github.com/plotly/datasets/raw/master/tips.csv"
df = pd.read_csv(URL)
df["size"].value_counts()
df.groupby("size").total_bill.mean()
df.apply(list, axis=1)
41 changes: 41 additions & 0 deletions python/cudf/cudf_pandas_tests/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import os
import subprocess

from cudf.pandas import LOADED, Profiler

if not LOADED:
Expand Down Expand Up @@ -68,3 +71,41 @@ def test_profiler_fast_slow_name_mismatch():
with Profiler():
df = pd.DataFrame({"a": [1, 2, 3], "b": [3, 4, 5]})
df.iloc[0, 1] = "foo"


def test_profiler_commandline():
data_directory = os.path.dirname(os.path.abspath(__file__))
# Create a copy of the current environment variables
env = os.environ.copy()
# Setting the 'COLUMNS' environment variable to a large number
# because the terminal output shouldn't be compressed for
# text validations below.
env["COLUMNS"] = "10000"

sp_completed = subprocess.run(
[
"python",
"-m",
"cudf.pandas",
"--profile",
data_directory + "/data/profile_basic.py",
],
capture_output=True,
text=True,
env=env,
)
assert sp_completed.returncode == 0
output = sp_completed.stdout

for string in [
"Total time",
"Stats",
"Function",
"GPU ncalls",
"GPU cumtime",
"GPU percall",
"CPU ncalls",
"CPU cumtime",
"CPU percall",
]:
assert string in output

0 comments on commit b18c45c

Please sign in to comment.