示例#1
0
 def data(self, val: pd.DataFrame) -> None:
     """Adjust data columns to match corrected attribute names."""
     lowered_columns = [
         correct_case(col, False) for col in val.columns.to_list()
     ]
     attrs = [attr.name for attr in self.attributes]
     lowered_attrs = [correct_case(attr, False) for attr in attrs]
     val.columns = [
         attrs[lowered_attrs.index(col)] for col in lowered_columns
     ]
     self._data = val
示例#2
0
    def case(self, val: str) -> str:
        """Does the up-front case correction.
        SnowShu uses the default source case as the "case insensitive" fold.
        Args:
            val: The value to case correct.
        Returns:
            The corrected string.
        """
        if self.preserve_case:
            return val

        return correct_case(val, self.default_case == 'upper')
示例#3
0
    def data(self, val: pd.DataFrame) -> None:
        """ Setter for the relation's dataframe

            Adjusts data columns to match corrected attribute names and
            fixes mismatched datatypes
        """
        lowered_columns = [
            correct_case(col, False) for col in val.columns.to_list()
        ]
        attrs = [attr.name for attr in self.attributes]
        lowered_attrs = [correct_case(attr, False) for attr in attrs]
        val.columns = [
            attrs[lowered_attrs.index(col)] for col in lowered_columns
        ]

        # handle the fact that pandas.read_sql may not preserve json type on load
        for attr in self.attributes:
            if isinstance(attr.data_type.sqlalchemy_type, JSON):
                transform_func = (lambda v: json.loads(v)
                                  if isinstance(v, str) else v)
                val[attr.name] = val[attr.name].transform(func=transform_func)

        self._data = val
示例#4
0
 def _correct_case(self, val: str) -> str:
     """The base case correction method for a source adapter.
     """
     return val if self.preserve_case else correct_case(
         val, self.DEFAULT_CASE == 'upper')
示例#5
0
 def leave_test_suite(under_test, upper):
     for item in under_test:
         correct_case(item, upper) == item
示例#6
0
 def correct_test_suite(under_test, upper):
     for item in under_test:
         expected = item.upper() if upper else item.lower()
         assert correct_case(item, upper) == expected