From b18c45c3143ac1ea35f7de620b4f896b38a0af73 Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Tue, 28 Nov 2023 17:25:35 +0000 Subject: [PATCH] Fix a typo and add tests --- python/cudf/cudf/pandas/__main__.py | 2 +- .../cudf_pandas_tests/data/profile_basic.py | 9 ++++ .../cudf/cudf_pandas_tests/test_profiler.py | 41 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 python/cudf/cudf_pandas_tests/data/profile_basic.py diff --git a/python/cudf/cudf/pandas/__main__.py b/python/cudf/cudf/pandas/__main__.py index 02e8e960678..fb8569fa1d0 100644 --- a/python/cudf/cudf/pandas/__main__.py +++ b/python/cudf/cudf/pandas/__main__.py @@ -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 diff --git a/python/cudf/cudf_pandas_tests/data/profile_basic.py b/python/cudf/cudf_pandas_tests/data/profile_basic.py new file mode 100644 index 00000000000..fed4058090c --- /dev/null +++ b/python/cudf/cudf_pandas_tests/data/profile_basic.py @@ -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) diff --git a/python/cudf/cudf_pandas_tests/test_profiler.py b/python/cudf/cudf_pandas_tests/test_profiler.py index a947d67b724..4921446ab6b 100644 --- a/python/cudf/cudf_pandas_tests/test_profiler.py +++ b/python/cudf/cudf_pandas_tests/test_profiler.py @@ -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: @@ -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