Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setdefault to handle default kwargs more cleanly #360

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ribs/archives/_cvt_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ def __init__(self,
# particularly if they want higher quality clusters.
self._k_means_kwargs = ({} if k_means_kwargs is None else
k_means_kwargs.copy())
if "n_init" not in self._k_means_kwargs:
self._k_means_kwargs.setdefault(
# Only run one iter to be fast.
self._k_means_kwargs["n_init"] = 1
if "init" not in self._k_means_kwargs:
# The default, "k-means++", takes very long to init.
self._k_means_kwargs["init"] = "random"
if "algorithm" not in self._k_means_kwargs:
self._k_means_kwargs["algorithm"] = "lloyd"
if "random_state" not in self._k_means_kwargs:
self._k_means_kwargs["random_state"] = seed
"n_init",
1)
self._k_means_kwargs.setdefault(
# The default "k-means++" takes very long to init.
"init",
"random")
self._k_means_kwargs.setdefault("algorithm", "lloyd")
self._k_means_kwargs.setdefault("random_state", seed)

self._use_kd_tree = use_kd_tree
self._centroid_kd_tree = None
Expand Down
8 changes: 3 additions & 5 deletions ribs/visualize/_parallel_axes_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,9 @@ def parallel_axes_plot(archive,
mappable = ScalarMappable(cmap=cmap)
mappable.set_clim(vmin, vmax)

# Default colorbar settings.
# Add default colorbar settings.
cbar_kwargs = {} if cbar_kwargs is None else cbar_kwargs.copy()
if "orientation" not in cbar_kwargs:
cbar_kwargs["orientation"] = "horizontal"
if "pad" not in cbar_kwargs:
cbar_kwargs["pad"] = 0.1
cbar_kwargs.setdefault("orientation", "horizontal")
cbar_kwargs.setdefault("pad", 0.1)

set_cbar(mappable, host_ax, cbar, cbar_kwargs)
Loading