diff --git a/ultraplot/internals/inputs.py b/ultraplot/internals/inputs.py index 25bcbf6ec..ef3fe3876 100644 --- a/ultraplot/internals/inputs.py +++ b/ultraplot/internals/inputs.py @@ -247,6 +247,7 @@ def _from_data(data, *args): if data is None: return args = list(args) + found_in_data = False for i, arg in enumerate(args): if isinstance(arg, str): try: @@ -255,6 +256,13 @@ def _from_data(data, *args): pass else: args[i] = array + found_in_data = True + + # If only one argument and it wasn't found in data, return the original scalar + # This prevents scalar values like "none" from becoming ["none"] + if len(args) == 1 and not found_in_data: + return args[0] + return args diff --git a/ultraplot/tests/test_1dplots.py b/ultraplot/tests/test_1dplots.py index 84debe9cc..eee2178bb 100644 --- a/ultraplot/tests/test_1dplots.py +++ b/ultraplot/tests/test_1dplots.py @@ -295,6 +295,46 @@ def test_scatter_args(rng): return fig +@pytest.mark.mpl_image_compare +def test_scatter_edgecolor_single_row(): + """ + Test that edgecolor is properly handled for single-row DataFrame input. + This is a regression test for issue #324. + """ + import pandas as pd + + # Create test data + df_multi = pd.DataFrame({"x": [1, 2], "y": [1, 2], "sizes": [300, 300]}) + df_single = pd.DataFrame({"x": [2], "y": [2], "sizes": [300]}) + + fig, axs = uplt.subplots(ncols=3, share=0) + + # Test multiple rows with alpha + result1 = axs[0].scatter( + "x", "y", s="sizes", data=df_multi, fc="red8", ec="none", alpha=1 + ) + + # Test single row with alpha (the problematic case) + result2 = axs[1].scatter( + "x", "y", s="sizes", data=df_single, fc="red8", ec="none", alpha=1 + ) + + # Test single row without alpha + result3 = axs[2].scatter("x", "y", s="sizes", data=df_single, fc="red8", ec="none") + + # Verify that edgecolors are correctly set to no edges for all cases + # An empty array means no edges (which is what 'none' should produce) + assert len(result1.get_edgecolors()) == 0, "Multiple rows should have no edges" + assert ( + len(result2.get_edgecolors()) == 0 + ), "Single row with alpha should have no edges" + assert ( + len(result3.get_edgecolors()) == 0 + ), "Single row without alpha should have no edges" + + return fig + + @pytest.mark.mpl_image_compare def test_scatter_inbounds(): """