Skip to content

Commit

Permalink
refactor: Remove copy_keys utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Sep 17, 2024
1 parent 621195c commit b09cc0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
21 changes: 0 additions & 21 deletions plotnine/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,27 +733,6 @@ def make_line_segments(
return segments


def copy_keys(source, destination, keys=None):
"""
Add keys in source to destination
Parameters
----------
source : dict
destination: dict
keys : None | iterable
The keys in source to be copied into destination. If
None, then `keys = destination.keys()`
"""
if keys is None:
keys = destination.keys()
for k in set(source) & set(keys):
destination[k] = source[k]
return destination


def get_kwarg_names(func):
"""
Return a list of valid kwargs to function func
Expand Down
9 changes: 6 additions & 3 deletions plotnine/geoms/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from itertools import chain, repeat

from .._utils import (
copy_keys,
data_mapping_as_kwargs,
is_list_like,
remove_missing,
Expand Down Expand Up @@ -83,8 +82,12 @@ def __init__(
self._kwargs = kwargs # Will be used to create stat & layer

# separate aesthetics and parameters
self.aes_params = copy_keys(kwargs, {}, self.aesthetics())
self.params = copy_keys(kwargs, deepcopy(self.DEFAULT_PARAMS))
self.aes_params = {
ae: kwargs[ae] for ae in self.aesthetics() & set(kwargs)
}
self.params = self.DEFAULT_PARAMS | {
k: v for k, v in kwargs.items() if k in self.DEFAULT_PARAMS
}
self.mapping = kwargs["mapping"]
self.data = kwargs["data"]
self._stat = stat.from_geom(self)
Expand Down
7 changes: 4 additions & 3 deletions plotnine/stats/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from .._utils import (
check_required_aesthetics,
copy_keys,
data_mapping_as_kwargs,
groupby_apply,
remove_missing,
Expand Down Expand Up @@ -75,10 +74,12 @@ def __init__(
):
kwargs = data_mapping_as_kwargs((data, mapping), kwargs)
self._kwargs = kwargs # Will be used to create the geom
self.params = copy_keys(kwargs, deepcopy(self.DEFAULT_PARAMS))
self.params = self.DEFAULT_PARAMS | {
k: v for k, v in kwargs.items() if k in self.DEFAULT_PARAMS
}
self.DEFAULT_AES = aes(**self.DEFAULT_AES)
self.aes_params = {
ae: kwargs[ae] for ae in (self.aesthetics() & kwargs.keys())
ae: kwargs[ae] for ae in self.aesthetics() & set(kwargs)
}

@staticmethod
Expand Down

0 comments on commit b09cc0f

Please sign in to comment.