def guess_domain(self): """ return the index of the domain the associated series is thought to best match. if there are less than twenty unique items in the series the guess is enumerated if it's numeric the guess is range. else it's unrepresentable Returns ------- int : index of the domain the associated series is thought to best match """ # given a series of data take a guess as to which # domain type is appropriate if self.series is not None: if self.nodata is not None: clean_series = data_io.clean_nodata(self.series, self.nodata) else: clean_series = self.series uniques = clean_series.unique() if np.issubdtype(clean_series.dtype, np.number): return 1 # range elif len(uniques) < 20: return 0 # enumerated else: return 3 # unrepresentable # without a series to introspect we're going to default to udom return 3 # unrepresentable
def populate_domain_content(self, which='guess'): """ Fill out this widget with the content from it's associated series Parameters ---------- which : str, optional, one of 'guess' or the index to force if guess introspect the series associated with this attribute and make a best guess as to which domain to use. Returns ------- None """ self.clear_domain() if which == 'guess': self.sniff_nodata() index = self.guess_domain() else: index = which self.ui.comboBox.setCurrentIndex(index) if index == 0: self.domain = edom_list.EdomList(parent=self) elif index == 1: self.domain = rdom.Rdom(parent=self) elif index == 2: self.domain = codesetd.Codesetd(parent=self) else: self.domain = udom.Udom(parent=self) if self._domain_content[index] is not None: # This domain has been used before, display previous content self.domain.from_xml(self._domain_content[index]) elif self.series is not None and index == 0: clean_series = data_io.clean_nodata(self.series, self.nodata) uniques = clean_series.unique() if len(uniques) > 100: msg = "There are more than 100 unique values in this field." msg += "\n This tool cannot smoothly display that many " \ "entries. " msg += "\nTypically an enumerated domain is not used with " \ "that many unique entries." msg += "\n\nOnly the first one hundred are displayed below!" msg += "\nYou will likely want to change the domain to one " \ "of the other options." QMessageBox.warning(self, "Too many unique entries", msg) self.domain.populate_from_list(uniques[:101]) else: self.domain.populate_from_list(uniques) elif self.series is not None and index == 1: clean_series = data_io.clean_nodata(self.series, self.nodata) try: self.domain.ui.fgdc_rdommin.setText(str(clean_series.min())) except: self.domain.ui.fgdc_rdommin.setText('') try: self.domain.ui.fgdc_rdommax.setText(str(clean_series.max())) except: self.domain.ui.fgdc_rdommax.setText('') if not np.issubdtype(clean_series.dtype, np.number): msg = 'Caution! The contents of this column are stored in the' \ ' data source as "text". The use of a range domain ' \ 'type on text columns might give unexpected results, ' \ 'especially for columns that contain date information.' msgbox = QMessageBox(QMessageBox.Warning, "Range domain on text field", msg) utils.set_window_icon(msgbox) msgbox.exec_() self.ui.attrdomv_contents.layout().addWidget(self.domain)