create_small_multiples crashes when commodities fit in one row (n <= cols) #158
Description
Status: confirmed (local repro on main 5d9aa37 and on PR #157 head 2a7596e; pre-existing, not introduced by #157). Priority P2, area: visualization.
PriceVisualizer.create_small_multiples() raises whenever all commodities fit in one row (len(commodities) <= cols, default cols=3), which is the most common call.
Repro (matplotlib 3.11.2, numpy 2.5.4, Python 3.14, historical.get stubbed with 60 daily points):
c.viz.create_small_multiples(["A", "B"]) # n=2, cols=3 -> rows=1
AttributeError: 'numpy.ndarray' object has no attribute 'spines'
oilpriceapi/visualization.py:484 TufteStyle.apply(ax)
c.viz.create_small_multiples(["A", "B", "C", "D"]) # rows=2 -> returns Figure
Cause (oilpriceapi/visualization.py ~L452-469): when rows == 1, plt.subplots(1, cols) returns a 1-D array, the code wraps it as axes = [axes], then indexes axes[col]. For col=0 that is the whole ndarray; for col>=1 it would be an IndexError. The cols == 1 branch has the same shape problem.
Fix: fig, axes = plt.subplots(rows, cols, ..., squeeze=False) and always index axes[row][col]; drop the two wrapping branches. Add a test for n=1, n=cols, n=cols+1 and cols=1.
Activity