posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.85k stars 91 forks source link

Plotnine plots printing on every console execution #4819

Open jthomasmock opened 2 months ago

jthomasmock commented 2 months ago

System details:

Positron and OS details: Positron Version: 2024.09.0 (Universal) build 85

Code - OSS Version: 1.93.0 Commit: d3f087daf5cc7eaa3253ccdfa5dd4b9baff97da8 Date: 2024-09-25T16:45:02.746Z Electron: 30.4.0 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Darwin arm64 24.0.0

Interpreter details:

Python script with 3.12.0 and plotnine==0.13.6

Full set of Packages ``` appnope==0.1.4 asttokens==2.4.1 attrs==24.2.0 babel==2.16.0 comm==0.2.2 commonmark==0.9.1 contourpy==1.3.0 cycler==0.12.1 debugpy==1.8.6 decorator==5.1.1 executing==2.1.0 fastjsonschema==2.20.0 fonttools==4.54.1 great-tables==0.11.1 htmltools==0.5.3 importlib_metadata==8.5.0 importlib_resources==6.4.5 ipykernel==6.29.5 ipython==8.27.0 jedi==0.19.1 jsonschema==4.23.0 jsonschema-specifications==2023.12.1 jupyter_client==8.6.3 jupyter_core==5.7.2 kiwisolver==1.4.7 matplotlib==3.9.2 matplotlib-inline==0.1.7 mizani==0.11.4 nbformat==5.10.4 nest-asyncio==1.6.0 numpy==2.1.1 packaging==24.1 pandas==2.2.3 parso==0.8.4 patsy==0.5.6 pexpect==4.9.0 pillow==10.4.0 platformdirs==4.3.6 plotly==5.24.1 plotnine==0.13.6 polars==1.8.2 prompt_toolkit==3.0.47 psutil==6.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyarrow==17.0.0 Pygments==2.18.0 pyparsing==3.1.4 python-dateutil==2.9.0.post0 pytz==2024.2 pyzmq==26.2.0 referencing==0.35.1 rpds-py==0.20.0 scipy==1.14.1 six==1.16.0 stack-data==0.6.3 statsmodels==0.14.3 tenacity==9.0.0 tornado==6.4.1 traitlets==5.14.3 typing_extensions==4.12.2 tzdata==2024.2 wcwidth==0.2.13 zipp==3.20.2 ```

Describe the issue:

https://github.com/user-attachments/assets/263d8c75-9987-4517-ba56-ed01a07d66bb

Plotnine plots are reprinted and throw an error every time any Python code is executed:

/Users/thomasmock/.pyenv/versions/3.12.0/lib/python3.12/pprint.py:629: FutureWarning: Using repr(plot) to draw and show the plot figure is deprecated and will be removed in a future version. Use plot.show().

Same error with plot.show()

Steps to reproduce the issue:

Run the following Python script via console and then execute 1+1 in the console or any other code.

import pandas as pd
import numpy as np
from plotnine import ggplot, aes, geom_point, geom_smooth, theme_minimal, labs

# Create a sample dataset
np.random.seed(42)
data = pd.DataFrame({
    'x': np.random.rand(100) * 10,
    'y': np.random.rand(100) * 10 + np.random.rand(100) * 5
})

# Create the plot
plot = (
    ggplot(data, aes('x', 'y')) +
    geom_point(color='blue', alpha=0.6) +
    geom_smooth(method='lm', color='red', se=True) +
    theme_minimal() +
    labs(title='Basic Scatter Plot with Trend Line',
         x='X-axis', y='Y-axis')
)

# Display the plot
print(plot)

Expected or desired behavior:

No warning/error and no reprinting unless requested.

Were there any error messages in the UI, Output panel, or Developer Tools console?

jmcphers commented 2 months ago

Could this be related to (or the same as) https://github.com/posit-dev/positron/issues/4456?

jthomasmock commented 2 months ago

It does seem very similar!