Пример #1
0
    def guess_domain(self, force=False):

        cbo = self.ui.comboBox

        if self.series is not None:
            #set the current index to a non-choice below so that the
            #setCurrentIndex fires our change index
            cbo.setCurrentIndex(2)
            uniques = self.series.unique()
            if (not force and len(uniques) < 15) \
                    or force=='enumerated':
                self.enumerateds = []
                enumerated = edom_list.EdomList()
                enumerated.populate_from_list(uniques)

                self.domain = enumerated
                cbo.setCurrentIndex(0)

            elif (not force and (self.series.dtype == np.float or \
                            self.series.dtype == np.int)) or \
                    force=='range':
                self.domain = rdom.Rdom()
                self.domain.ui.fgdc_rdommin.setText(str(self.series.min()))
                self.domain.ui.fgdc_rdommax.setText(str(self.series.max()))
                cbo.setCurrentIndex(1)
            else:
                self.domain = udom.Udom()
                cbo.setCurrentIndex(3)

        self.ui.attrdomv_contents.layout().addWidget(self.domain)
Пример #2
0
    def guess_domain(self):

        cbo = self.ui.comboBox

        if self.series is not None:
            uniques = self.series.unique()
            if len(uniques) < 15:
                self.enumerateds = []
                enumerated = edom_list.EdomList()
                enumerated.populate_from_list(uniques)

                self.domain = enumerated
                cbo.setCurrentIndex(0)

            elif self.series.dtype == np.float or \
                            self.series.dtype == np.int:
                self.domain = rdom.Rdom()
                self.domain.ui.fgdc_rdommin.setText(str(self.series.min()))
                self.domain.ui.fgdc_rdommax.setText(str(self.series.max()))
                cbo.setCurrentIndex(1)
            else:
                self.domain = udom.Udom()
                cbo.setCurrentIndex(3)

        self.ui.fgdc_attrdomv.layout().addWidget(self.domain)
Пример #3
0
    def change_domain(self, e):

        self.clear_domain()

        domain = self.ui.comboBox.currentText().lower()
        if 'enumerated' in domain:
            self.domain = edom_list.EdomList(parent=self)
            if self.series is not None:
                uniques = self.series.unique()
                self.domain.populate_from_list(uniques)
        elif 'range' in domain:
            self.domain = rdom.Rdom(parent=self)
            if self.series is not None:
                try:
                    series_min = self.series.min()
                    series_max = self.series.max()
                except TypeError:
                    series_min = ''
                    series_max = ''

                self.domain.ui.fgdc_rdommin.setText(str(series_min))
                self.domain.ui.fgdc_rdommax.setText(str(series_max))
        elif 'codeset' in domain:
            self.domain = codesetd.Codesetd(parent=self)
        elif 'unrepresentable' in domain:
            self.domain = udom.Udom(parent=self)

        self.ui.fgdc_attrdomv.layout().addWidget(self.domain)
Пример #4
0
    def change_domain(self, index):

        previous_domain = self.ui.comboBox.itemText(self._previous_index)
        self._domain_content[previous_domain] = self.domain._to_xml()

        self._previous_index = index
        self.clear_domain()

        domain = self.ui.comboBox.currentText().lower()

        if 'enumerated' in domain:
            self.domain = edom_list.EdomList(parent=self)
            if self._domain_content[
                    'Enumerated (Categorical Data)'] is not None:
                self.domain._from_xml(
                    self._domain_content['Enumerated (Categorical Data)'])
            elif self.series is not None:
                uniques = self.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 'range' in domain:
            self.domain = rdom.Rdom(parent=self)
            if self._domain_content['Range (Numeric data)'] is not None:
                self.domain._from_xml(
                    self._domain_content['Range (Numeric data)'])
            elif self.series is not None:
                try:
                    series_min = self.series.min()
                    series_max = self.series.max()
                except TypeError:
                    series_min = ''
                    series_max = ''
                self.domain.ui.fgdc_rdommin.setText(str(series_min))
                self.domain.ui.fgdc_rdommax.setText(str(series_max))
        elif 'codeset' in domain:
            self.domain = codesetd.Codesetd(parent=self)
            if self._domain_content[
                    'Codeset (Published Categories)'] is not None:
                self.domain._from_xml(
                    self._domain_content['Codeset (Published Categories)'])
        elif 'unrepresentable' in domain:
            self.domain = udom.Udom(parent=self)
            if self._domain_content[
                    'Unrepresentable (None of the above)'] is not None:
                self.domain._from_xml(
                    self._domain_content['Unrepresentable (None of the above)']
                )
        else:
            pass

        self.ui.attrdomv_contents.layout().addWidget(self.domain)
Пример #5
0
    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)
Пример #6
0
    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':
            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:
            uniques = self.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:
            try:
                self.domain.ui.fgdc_rdommin.setText(str(self.series.min()))
            except:
                self.domain.ui.fgdc_rdommin.setText('')
            try:
                self.domain.ui.fgdc_rdommax.setText(str(self.series.max()))
            except:
                self.domain.ui.fgdc_rdommax.setText('')

        self.ui.attrdomv_contents.layout().addWidget(self.domain)