How to use the datalab.utils.commands function in datalab

To help you get started, we’ve selected a few datalab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googledatalab / pydatalab / datalab / mlalpha / commands / _ml.py View on Github external
output = """
Local Run Command:

%s
%s
[Description]:
%s

Cloud Run Command:

%s
%s
[Description]:
%s
""" % (command_local, args_local, docstring_local, command_cloud, args_cloud, docstring_cloud)
      return datalab.utils.commands.render_text(output, preformatted=True)

    env = datalab.utils.commands.notebook_environment()
    func_args = datalab.utils.commands.parse_config(cell, env)
    if args['cloud'] is True:
      return pr.run_func(cloud_func_name, func_args)
    else:
      return pr.run_func(local_func_name, func_args)
github googledatalab / pydatalab / google / datalab / utils / commands / _chart_data.py View on Github external
if legacy is not None:
      data_source = datalab.utils.commands._utils._data_sources
    else:
      data_source = _utils._data_sources

    source_index = int(source_index)
    if source_index >= len(data_source):  # Can happen after e.g. kernel restart
      # TODO(gram): get kernel restart events in charting.js and disable any refresh timers.
      print('No source %d' % source_index)
      return IPython.core.display.JSON({'data': {}})
    source = data_source[source_index]
    schema = None

    controls = metadata['controls'] if 'controls' in metadata else {}
    if legacy is not None:
      data, _ = datalab.utils.commands.get_data(
          source, fields, controls, first_row, count, schema)
    else:
      data, _ = _utils.get_data(source, fields, controls, first_row, count, schema)
  except Exception as e:
    google.datalab.utils.print_exception_with_last_stack(e)
    print('Failed with exception %s' % e)
    data = {}

  # TODO(gram): The old way - commented out below - has the advantage that it worked
  # for datetimes, but it is strictly wrong. The correct way below may have issues if the
  # chart has datetimes though so test this.
  return IPython.core.display.JSON({'data': data, 'refresh_interval': refresh, 'options': options})
  # return IPython.core.display.JSON(json.dumps({'data': data},