Handles the creation of ExpectationBuilder when a dictionary item access.
770217
def key_read(self, sender, name):
        ""
        return ExpectationBuilder(self.sender, self.delegate, self.add_invocation, self.add_expectations, '__getitem__')(name)
681390
def handle_new_selection(self, items):
        
        if items is None:
            items = ()
        elif not hasattr(items, "__iter__"):
            items = (items,)
        models = set(item.model for item in items)
        self._selection.handle_new_selection(models)
839074
def expectation_payload(prep_prog, operator_programs, random_seed):
    """"""
    if operator_programs is None:
        operator_programs = [Program()]

    if not isinstance(prep_prog, Program):
        raise TypeError("prep_prog variable must be a Quil program object")

    payload = {'type': TYPE_EXPECTATION,
               'state-preparation': prep_prog.out(),
               'operators': [x.out() for x in operator_programs]}

    if random_seed is not None:
        payload['rng-seed'] = random_seed

    return payload
748939
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'generic' in _dict:
            args['generic'] = [
                DialogRuntimeResponseGeneric._from_dict(x)
                for x in (_dict.get('generic'))
            ]
        if 'intents' in _dict:
            args['intents'] = [
                RuntimeIntent._from_dict(x) for x in (_dict.get('intents'))
            ]
        if 'entities' in _dict:
            args['entities'] = [
                RuntimeEntity._from_dict(x) for x in (_dict.get('entities'))
            ]
        if 'actions' in _dict:
            args['actions'] = [
                DialogNodeAction._from_dict(x) for x in (_dict.get('actions'))
            ]
        if 'debug' in _dict:
            args['debug'] = MessageOutputDebug._from_dict(_dict.get('debug'))
        if 'user_defined' in _dict:
            args['user_defined'] = _dict.get('user_defined')
        return cls(**args)
524703
def column_aggregate_expectation(cls, func):
        
        if PY3:
            argspec = inspect.getfullargspec(func)[0][1:]
        else:
            argspec = inspect.getargspec(func)[0][1:]

        @cls.expectation(argspec)
        @wraps(func)
        def inner_wrapper(self, column, result_format=None, *args, **kwargs):

            if result_format is None:
                result_format = self.default_expectation_args["result_format"]

            result_format = parse_result_format(result_format)

            evaluation_result = func(self, column, *args, **kwargs)

            if 'success' not in evaluation_result:
                raise ValueError(
                    "Column aggregate expectation failed to return required information: success")

            if 'result' not in evaluation_result:
                raise ValueError(
                    "Column aggregate expectation failed to return required information: result")

            if 'observed_value' not in evaluation_result['result']:
                raise ValueError(
                    "Column aggregate expectation failed to return required information: result.observed_value")

            return_obj = {
                'success': bool(evaluation_result['success'])
            }

            if result_format['result_format'] == 'BOOLEAN_ONLY':
                return return_obj

            # Use the element and null count information from a column_aggregate_expectation if it is needed
            # it anyway to avoid an extra trip to the database

            if 'element_count' not in evaluation_result and 'null_count' not in evaluation_result:
                count_query = sa.select([
                    sa.func.count().label('element_count'),
                    sa.func.sum(
                        sa.case([(sa.column(column) == None, 1)], else_=0)
                    ).label('null_count'),
                ]).select_from(self._table)

                count_results = dict(
                    self.engine.execute(count_query).fetchone())

                # Handle case of empty table gracefully:
                if "element_count" not in count_results or count_results["element_count"] is None:
                    count_results["element_count"] = 0
                if "null_count" not in count_results or count_results["null_count"] is None:
                    count_results["null_count"] = 0

                return_obj['result'] = {
                    'observed_value': evaluation_result['result']['observed_value'],
                    "element_count": count_results['element_count'],
                    "missing_count": count_results['null_count'],
                    "missing_percent": count_results['null_count'] / count_results['element_count'] if count_results['element_count'] > 0 else None
                }
            else:
                return_obj['result'] = {
                    'observed_value': evaluation_result['result']['observed_value'],
                    "element_count": evaluation_result["element_count"],
                    "missing_count": evaluation_result["null_count"],
                    "missing_percent": evaluation_result['null_count'] / evaluation_result['element_count'] if evaluation_result['element_count'] > 0 else None
                }

            if result_format['result_format'] == 'BASIC':
                return return_obj

            if 'details' in evaluation_result['result']:
                return_obj['result']['details'] = evaluation_result['result']['details']

            if result_format['result_format'] in ["SUMMARY", "COMPLETE"]:
                return return_obj

            raise ValueError("Unknown result_format %s." %
                             (result_format['result_format'],))

        return inner_wrapper
662769
def create_new_item(*args)
      if block_given?
        new_item = yield(*args)
      else
        new_item = create(*args)
      end

      transform_item(new_item)
    end
60954
def _create_options(self, items):
        
        return OrderedDict(map(lambda x: (x.name, x),
                           coerce_to_list(items, self.preprocess)))
527460
def from_dict(cls, d):
        """"""
        return cls(**{k: v for k, v in d.items() if k in cls.ENTRIES})
92542
def expected_value(rules, multi_keys)
      multi_keys.inject(rules) { |o, key| o[key] }
    end
1106108
def _expectation(p, kern, feat, mean, none, nghp=None):
    
    Xmu, Xcov = p.mu, p.cov

    with tf.control_dependencies([tf.assert_equal(
            tf.shape(Xmu)[1], tf.constant(kern.input_dim, settings.int_type),
            message="Currently cannot handle slicing in exKxz.")]):
        Xmu = tf.identity(Xmu)

    with params_as_tensors_for(kern, feat):
        N = tf.shape(Xmu)[0] - 1
        var_Z = kern.variance * feat.Z  # MxD
        tiled_Z = tf.tile(tf.expand_dims(var_Z, 0), (N, 1, 1))  # NxMxD
        eXX = Xcov[1, :-1] + (Xmu[:-1][..., None] * Xmu[1:][:, None, :])  # NxDxD
        return tf.matmul(tiled_Z, eXX)
562590
protected void setExpectation() {
		expectation = 0.0;
		for(Double d: insertStat.keySet()) {
			expectation += d*(insertStat.get(d)/observationCount);
		}
	}
513357
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'message_type' in _dict:
            args['message_type'] = _dict.get('message_type')
        if 'text' in _dict:
            args['text'] = _dict.get('text')
        if 'options' in _dict:
            args['options'] = MessageInputOptions._from_dict(
                _dict.get('options'))
        if 'intents' in _dict:
            args['intents'] = [
                RuntimeIntent._from_dict(x) for x in (_dict.get('intents'))
            ]
        if 'entities' in _dict:
            args['entities'] = [
                RuntimeEntity._from_dict(x) for x in (_dict.get('entities'))
            ]
        if 'suggestion_id' in _dict:
            args['suggestion_id'] = _dict.get('suggestion_id')
        return cls(**args)
840351
def handleTagChange( self, item ):
        
        # :note PySide == operator not defined for QListWidgetItem.  In this
        #       in this case, we're just checking if the object is the exact
        #       same, so 'is' works just fine.
        create_item = self.createItem()
        if item is create_item:
            self.addTag(create_item.text())
        
        elif self.isTagValid(item.text()):
            item.setText(item.text())
463896
def perform(self):
        
        last_value = None
        last_step = None

        while self.items.qsize():

            item = self.items.get()

            if item.flag == self.do:
                last_value = item.item(*item.args, **item.kwargs)
                last_step = item.message
            elif item.flag == self.expect:
                message = item.message
                local = {'value': last_value, 'expectation': item.item}
                expression = 'value {operator} expectation'.format(operator=item.operator)
                result = eval(expression, local)

                # Format the error message
                format_vars = {
                    'actual': last_value,
                    'expected': item.item,
                    'step': last_step,
                    'operator': item.operator
                }

                for var, val in format_vars.iteritems():
                    message = message.replace('{' + str(var) + '}', str(val))

                assert result, message

        return last_value
933360
public static <T, U> DictionaryFeatureVectorGenerator<T, U> createFromDataWithThreshold(
      Collection<T> data, FeatureGenerator<T, U> generator, int occurrenceThreshold) {
    CountAccumulator<U> featureOccurrenceCounts = FeatureGenerators.getFeatureCounts(generator, data);
    IndexedList<U> features = new IndexedList<U>();
    features.addAll(featureOccurrenceCounts.getKeysAboveCountThreshold(occurrenceThreshold));
    return new DictionaryFeatureVectorGenerator<T, U>(features, generator, true);
  }
496425
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'input' in _dict:
            args['input'] = MessageInput._from_dict(_dict.get('input'))
        if 'intents' in _dict:
            args['intents'] = [
                RuntimeIntent._from_dict(x) for x in (_dict.get('intents'))
            ]
        if 'entities' in _dict:
            args['entities'] = [
                RuntimeEntity._from_dict(x) for x in (_dict.get('entities'))
            ]
        return cls(**args)
1028423
public static void assertEquals(Object expected, Object actual) {
        assertEquals(expected, actual, "Expected value " + expected + " but got " + actual);
    }