def _compare_feature_dicts(a_dict, b_dict): # We can't compare entityset dictionaries because variable lists are not # guaranteed to be in the same order. es_a = description_to_entityset(a_dict.pop('entityset')) es_b = description_to_entityset(b_dict.pop('entityset')) assert es_a == es_b assert a_dict == b_dict
def _check_schema_version(version, es, error_text): entities = {entity.id: serialize.entity_to_description(entity) for entity in es.entities} relationships = [relationship.to_dictionary() for relationship in es.relationships] dictionary = { 'schema_version': version, 'id': es.id, 'entities': entities, 'relationships': relationships, } if error_text: with pytest.raises(RuntimeError) as excinfo: deserialize.description_to_entityset(dictionary) assert error_text == str(excinfo.value) else: deserialize.description_to_entityset(dictionary)
def metadata(self): '''Returns the metadata for this EntitySet. The metadata will be recomputed if it does not exist.''' if self._data_description is None: description = serialize.entityset_to_description(self) self._data_description = deserialize.description_to_entityset(description) return self._data_description
def _check_schema_version(version, es, warning_text): entities = { entity.id: serialize.entity_to_description(entity) for entity in es.entities } relationships = [ relationship.to_dictionary() for relationship in es.relationships ] dictionary = { 'schema_version': version, 'id': es.id, 'entities': entities, 'relationships': relationships, } if warning_text: with pytest.warns(UserWarning) as record: deserialize.description_to_entityset(dictionary) assert record[0].message.args[0] == warning_text else: deserialize.description_to_entityset(dictionary)
def _check_schema_version(version, es, warning_text, caplog, warning_type=None): entities = { entity.id: serialize.entity_to_description(entity) for entity in es.entities } relationships = [ relationship.to_dictionary() for relationship in es.relationships ] dictionary = { 'schema_version': version, 'id': es.id, 'entities': entities, 'relationships': relationships, } if warning_type == 'log' and warning_text: logger = logging.getLogger('featuretools') logger.propagate = True deserialize.description_to_entityset(dictionary) assert warning_text in caplog.text logger.propagate = False elif warning_type == 'warn' and warning_text: with pytest.warns(UserWarning) as record: deserialize.description_to_entityset(dictionary) assert record[0].message.args[0] == warning_text else: deserialize.description_to_entityset(dictionary)
def test_all_ww_logical_types(): logical_types = list_logical_types()['type_string'].to_list() dataframe = pd.DataFrame(columns=logical_types) es = EntitySet() ltype_dict = {ltype: ltype for ltype in logical_types} ltype_dict['ordinal'] = Ordinal(order=[]) es.add_dataframe(dataframe=dataframe, dataframe_name='all_types', index='integer', logical_types=ltype_dict) description = serialize.entityset_to_description(es) _es = deserialize.description_to_entityset(description) assert es.__eq__(_es, deep=True)
def test_with_custom_ww_logical_type(): class CustomLogicalType(LogicalType): pass ww_type_system.add_type(CustomLogicalType) columns = ['integer', 'natural_language', 'custom_logical_type'] dataframe = pd.DataFrame(columns=columns) es = EntitySet() ltype_dict = { 'integer': 'integer', 'natural_language': 'natural_language', 'custom_logical_type': CustomLogicalType, } es.add_dataframe(dataframe=dataframe, dataframe_name='custom_type', index='integer', logical_types=ltype_dict) description = serialize.entityset_to_description(es) _es = deserialize.description_to_entityset(description) assert isinstance( _es['custom_type'].ww.logical_types['custom_logical_type'], CustomLogicalType) assert es.__eq__(_es, deep=True)
def test_dask_entityset_description(dask_es): description = serialize.entityset_to_description(dask_es) _es = deserialize.description_to_entityset(description) assert dask_es.metadata.__eq__(_es, deep=True)