# Buggy code
def _compute_grid(coordinates, values, tooltip_mode):
    """
    Compute interpolation of data points on regular grid in Cartesian
    coordinates.

    Parameters
    ==========

    coordinates : array-like
        Barycentric coordinates of data points.
    values : 1-d array-like
        Data points, field to be represented as contours.
    tooltip_mode : str, 'proportions' or 'percents'
        Coordinates inside the ternary plot can be displayed either as
        proportions (adding up to 1) or as percents (adding up to 100).
    """
    A, B, C = _prepare_barycentric_coord(coordinates)
    M, invM = _transform_barycentric_cartesian()
    cartes_coord_points = np.einsum("ik, kj -> ij", M, np.stack((A, B, C)))
    xx, yy = cartes_coord_points[:2]
    x_min, x_max = xx.min(), xx.max()
    y_min, y_max = yy.min(), yy.max()
    # n_interp = max(100, int(np.sqrt(len(values))))
    n_interp = 20
    gr_x = np.linspace(x_min, x_max, n_interp)
    gr_y = np.linspace(y_min, y_max, n_interp)
    grid_x, grid_y = np.meshgrid(gr_x, gr_y)
    grid_z = griddata(
        cartes_coord_points[:2].T, values, (grid_x, grid_y), method="cubic"
    )
    bar_coords = np.einsum(
        "ik, kmn -> imn", invM, np.stack((grid_x, grid_y, np.ones(grid_x.shape)))
    )
    # invalidate the points outside of the reference triangle
    bar_coords[np.where(bar_coords < 0)] = 0  # None
    # recompute back cartesian coordinates with invalid positions
    xy1 = np.einsum("ik, kmn -> imn", M, bar_coords)
    is_nan = np.where(np.isnan(xy1[0]))
    grid_z[is_nan] = 0  # None
    tooltip = _tooltip(n_interp, bar_coords, grid_z, xy1, tooltip_mode)
    return grid_z, gr_x, gr_y, tooltip


# Traceback (TypeError)
Traceback (most recent call last):

File "<ipython-input-13-5fb02038c35f>", line 1, in <module>
import plotly

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\__init__.py", line 31, in <module>
from plotly import (plotly, dashboard_objs, graph_objs, grid_objs, tools,

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\__init__.py", line 10, in <module>
from . plotly import (

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\plotly.py", line 35, in <module>
from plotly.graph_objs import Scatter

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\__init__.py", line 82, in <module>
from ._figurewidget import FigureWidget

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\_figurewidget.py", line 12, in <module>
class FigureWidget(BaseFigureWidget):

TypeError: function() argument 1 must be code, not str

Traceback (most recent call last):

File "<ipython-input-13-5fb02038c35f>", line 1, in <module>
import plotly

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\__init__.py", line 31, in <module>
from plotly import (plotly, dashboard_objs, graph_objs, grid_objs, tools,

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\__init__.py", line 10, in <module>
from . plotly import (

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\plotly\plotly.py", line 35, in <module>
from plotly.graph_objs import Scatter

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\__init__.py", line 82, in <module>
from ._figurewidget import FigureWidget

File "C:\Users\Artemis\Anaconda3\lib\site-packages\plotly\graph_objs\_figurewidget.py", line 12, in <module>
class FigureWidget(BaseFigureWidget):

TypeError: function() argument 1 must be code, not str

# Fixed code
def _compute_grid(coordinates, values, tooltip_mode):
    """
    Compute interpolation of data points on regular grid in Cartesian
    coordinates.

    Parameters
    ==========

    coordinates : array-like
        Barycentric coordinates of data points.
    values : 1-d array-like
        Data points, field to be represented as contours.
    tooltip_mode : str, 'proportions' or 'percents'
        Coordinates inside the ternary plot can be displayed either as
        proportions (adding up to 1) or as percents (adding up to 100).
    """
    A, B, C = _prepare_barycentric_coord(coordinates)
    M, invM = _transform_barycentric_cartesian()
    cartes_coord_points = np.einsum("ik, kj -> ij", M, np.stack((A, B, C)))
    xx, yy = cartes_coord_points[:2]
    x_min, x_max = xx.min(), xx.max()
    y_min, y_max = yy.min(), yy.max()
    # n_interp = max(100, int(np.sqrt(len(values))))
    n_interp = 20
    gr_x = np.linspace(x_min, x_max, n_interp)
    gr_y = np.linspace(y_min, y_max, n_interp)
    grid_x, grid_y = np.meshgrid(gr_x, gr_y)
    grid_z = interpolate.griddata(
        cartes_coord_points[:2].T, values, (grid_x, grid_y), method="cubic"
    )
    bar_coords = np.einsum(
        "ik, kmn -> imn", invM, np.stack((grid_x, grid_y, np.ones(grid_x.shape)))
    )
    # invalidate the points outside of the reference triangle
    bar_coords[np.where(bar_coords < 0)] = 0  # None
    # recompute back cartesian coordinates with invalid positions
    xy1 = np.einsum("ik, kmn -> imn", M, bar_coords)
    is_nan = np.where(np.isnan(xy1[0]))
    grid_z[is_nan] = 0  # None
    tooltip = _tooltip(n_interp, bar_coords, grid_z, xy1, tooltip_mode)
    return grid_z, gr_x, gr_y, tooltip