Skip to content

Commit

Permalink
impl basic func guaranteeing DP
Browse files Browse the repository at this point in the history
  • Loading branch information
tak-ka3 committed Nov 28, 2023
1 parent e028d4c commit 1283550
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
)
import warnings

import numpy as np
import os
if os.environ.get("DP_NUMPY", "1") == "0":
import numpy as np
else:
import dp_numpy as np

from pandas._config import using_copy_on_write

Expand Down
10 changes: 10 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13367,6 +13367,16 @@ def make_doc(name: str, ndim: int) -> str:
see_also = _stat_func_see_also
examples = _sum_examples
kwargs = {"min_count": _min_count_stub}

elif name == "laplace_sum":
base_doc = _sum_prod_doc
desc = (
"Return the laplace sum of the values over the requested axis.\n\n"
"This is equivalent to the method ``dp_numpy.laplace_sum``."
)
see_also = _stat_func_see_also
examples = _sum_examples
kwargs = {"min_count": _min_count_stub}

elif name == "prod":
base_doc = _sum_prod_doc
Expand Down
19 changes: 19 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
else:
import dp_numpy as np

import numpy

from pandas._config import using_copy_on_write
from pandas._config.config import _get_option

Expand Down Expand Up @@ -6322,6 +6324,23 @@ def sum(
**kwargs,
):
return NDFrame.sum(self, axis, skipna, numeric_only, min_count, **kwargs)

@doc(make_doc("laplace_sum", ndim=1))
def laplace_sum(
self,
axis: Axis | None = None,
skipna: bool = True,
numeric_only: bool = False,
min_count: int = 0,
**kwargs,
):
assert type(self.values) == np.ndarray
eps = kwargs.get('eps')
kwargs.pop('eps')
self.values.unset_sensitive()
raw_val = NDFrame.sum(self, axis, skipna, numeric_only, min_count, **kwargs)
noised_val = numpy.random.laplace(loc=raw_val, scale=eps)
return noised_val

@doc(make_doc("prod", ndim=1))
def prod(
Expand Down

0 comments on commit 1283550

Please sign in to comment.