Пример #1
0
 def tearDown(self):
     ks.reset_option('test.config')
     del config._options_dict['test.config']
     del config._options_dict['test.config.list']
     del config._options_dict['test.config.float']
     del config._options_dict['test.config.int']
     del config._options_dict['test.config.int.none']
Пример #2
0
    def test_namespace_access(self):
        try:
            self.assertEqual(ks.options.compute.max_rows,
                             ks.get_option("compute.max_rows"))
            ks.options.compute.max_rows = 0
            self.assertEqual(ks.options.compute.max_rows, 0)
            self.assertTrue(isinstance(ks.options.compute, DictWrapper))

            wrapper = ks.options.compute
            self.assertEqual(wrapper.max_rows,
                             ks.get_option("compute.max_rows"))
            wrapper.max_rows = 1000
            self.assertEqual(ks.options.compute.max_rows, 1000)

            self.assertRaisesRegex(config.OptionError, "No such option",
                                   lambda: ks.options.compu)
            self.assertRaisesRegex(config.OptionError, "No such option",
                                   lambda: ks.options.compute.max)
            self.assertRaisesRegex(config.OptionError, "No such option",
                                   lambda: ks.options.max_rows1)

            with self.assertRaisesRegex(config.OptionError, "No such option"):
                ks.options.compute.max = 0
            with self.assertRaisesRegex(config.OptionError, "No such option"):
                ks.options.compute = 0
            with self.assertRaisesRegex(config.OptionError, "No such option"):
                ks.options.com = 0
        finally:
            ks.reset_option("compute.max_rows")
Пример #3
0
    def test_np_spark_compat_frame(self):
        # Use randomly generated dataFrame
        pdf = pd.DataFrame(np.random.randint(-100,
                                             100,
                                             size=(np.random.randint(100), 2)),
                           columns=["a", "b"])
        pdf2 = pd.DataFrame(np.random.randint(-100,
                                              100,
                                              size=(len(pdf),
                                                    len(pdf.columns))),
                            columns=["a", "b"])
        kdf = ks.from_pandas(pdf)
        kdf2 = ks.from_pandas(pdf2)

        for np_name, spark_func in unary_np_spark_mappings.items():
            np_func = getattr(np, np_name)
            if np_name not in self.blacklist:
                try:
                    # unary ufunc
                    self.assert_eq(np_func(pdf), np_func(kdf), almost=True)
                except Exception as e:
                    raise AssertionError("Test in '%s' function was failed." %
                                         np_name) from e

        for np_name, spark_func in binary_np_spark_mappings.items():
            np_func = getattr(np, np_name)
            if np_name not in self.blacklist:
                try:
                    # binary ufunc
                    self.assert_eq(np_func(pdf, pdf),
                                   np_func(kdf, kdf),
                                   almost=True)
                    self.assert_eq(np_func(pdf, 1),
                                   np_func(kdf, 1),
                                   almost=True)
                except Exception as e:
                    raise AssertionError("Test in '%s' function was failed." %
                                         np_name) from e

        # Test only top 5 for now. 'compute.ops_on_diff_frames' option increases too much time.
        try:
            set_option("compute.ops_on_diff_frames", True)
            for np_name, spark_func in list(
                    binary_np_spark_mappings.items())[:5]:
                np_func = getattr(np, np_name)
                if np_name not in self.blacklist:
                    try:
                        # binary ufunc
                        self.assert_eq(
                            np_func(pdf, pdf2).sort_index(),
                            np_func(kdf, kdf2).sort_index(),
                            almost=True,
                        )

                    except Exception as e:
                        raise AssertionError(
                            "Test in '%s' function was failed." %
                            np_name) from e
        finally:
            reset_option("compute.ops_on_diff_frames")
Пример #4
0
    def test_get_set_reset_option(self):
        self.assertEqual(ks.get_option('test.config'), 'default')

        ks.set_option('test.config', 'value')
        self.assertEqual(ks.get_option('test.config'), 'value')

        ks.reset_option('test.config')
        self.assertEqual(ks.get_option('test.config'), 'default')
Пример #5
0
    def test_unknown_option(self):
        with self.assertRaisesRegex(config.OptionError, 'No such option'):
            ks.get_option('unknown')

        with self.assertRaisesRegex(config.OptionError, "Available options"):
            ks.set_option('unknown', 'value')

        with self.assertRaisesRegex(config.OptionError, "test.config"):
            ks.reset_option('unknown')
Пример #6
0
    def test_unknown_option(self):
        with self.assertRaisesRegex(config.OptionError, 'No such key'):
            ks.get_option('unknown')

        with self.assertRaisesRegex(config.OptionError, "No such key"):
            ks.set_option('unknown', 'value')

        with self.assertRaisesRegex(config.OptionError, "No such key"):
            ks.reset_option('unknows')
Пример #7
0
 def tearDown(self):
     ks.reset_option('test.config')
     del config._registered_options['test.config']
     del config._registered_options['test.config.list']
     del config._registered_options['test.config.float']
     del config._registered_options['test.config.int']