Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HyukjinKwon committed Sep 19, 2019
1 parent cea7615 commit d740c34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 12 additions & 4 deletions databricks/koalas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,10 @@ def __setattr__(self, key, val):
k for k in d.keys() if all(x in k.split(".") for x in canonical_key.split("."))]
if len(candidates) == 1 and candidates[0] == canonical_key:
return set_option(canonical_key, val)
elif len(candidates) == 0:
else:
raise OptionError(
"No such option: '{}'. Available options are [{}]".format(
key, ", ".join(list(_options_dict.keys()))))
else:
return DictWrapper(d, canonical_key)

def __getattr__(self, key):
prefix = object.__getattribute__(self, "prefix")
Expand All @@ -344,7 +342,17 @@ def __getattr__(self, key):
return DictWrapper(d, canonical_key)

def __dir__(self):
return list(self.d.keys())
prefix = object.__getattribute__(self, "prefix")
d = object.__getattribute__(self, "d")

if prefix == "":
candidates = d.keys()
offset = 0
else:
candidates = [
k for k in d.keys() if all(x in k.split(".") for x in prefix.split("."))]
offset = len(prefix) + 1 # prefix (e.g. "compute.") to trim.
return [c[offset:] for c in candidates]


options = DictWrapper(_options_dict)
13 changes: 12 additions & 1 deletion databricks/koalas/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,19 @@ def test_namespace_access(self):

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")

def test_dir_options(self):
self.assertTrue("compute.max_rows" in dir(ks.options))
self.assertTrue("compute.default_index_type" in dir(ks.options))
self.assertTrue("plotting.sample_ratio" in dir(ks.options))

self.assertTrue("default_index_type" in dir(ks.options.compute))
self.assertTrue("sample_ratio" not in dir(ks.options.compute))

self.assertTrue("default_index_type" not in dir(ks.options.plotting))
self.assertTrue("sample_ratio" in dir(ks.options.plotting))

0 comments on commit d740c34

Please sign in to comment.