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

Added mypy support #308

Merged
merged 5 commits into from
Oct 13, 2020
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
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ jobs:
make check-coverage-python
env:
MIN_COVERAGE: 80
- name: Mypy test
run: |
pipenv install mypy
pipenv run mypy tests/ pydp/
pipenv run mypy examples/carrots_demo examples/restaurant_demo

# Need to see how to run the c++ code coverage
# - name: Check C++ code coverage
# if: runner.os == 'Linux' # Coverage will be the same on all systems so only running the check on Linux
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sphinx = "*"
sphinx-rtd-theme = "*"
gcovr = "*"
coverage = "*"
mypy = "*"

[packages]
jupyter = "*"
Expand Down
14 changes: 8 additions & 6 deletions examples/carrots_demo/carrots.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import statistics as s
from pathlib import Path

import pandas as pd
import pydp as dp # our privacy library
import pandas as pd # type: ignore
import pydp as dp # this library
from pydp.algorithms.laplacian import BoundedSum, BoundedMean, Count, Max

# Creating a class ClassReporter

from typing import Union

# Creating a class ClassReporter
class CarrotReporter:

# Function to read the csv file and creating a dataframe
Expand Down Expand Up @@ -62,14 +62,16 @@ def private_mean(self, privacy_budget: float) -> float:
return x.quick_result(list(self._df["carrots_eaten"]))

# Function to return the DP count of the number of animals who ate more than "limit" carrots.
def private_count_above(self, privacy_budget: float, limit: int) -> int:
def private_count_above(
self, privacy_budget: float, limit: int
) -> Union[int, float]:
x = Count(privacy_budget, dtype="int")
return x.quick_result(
list(self._df[self._df.carrots_eaten > limit]["carrots_eaten"])
)

# Function to return the DP maximum of the number of carrots eaten by any one animal.
def private_max(self, privacy_budget: float) -> int:
def private_max(self, privacy_budget: float) -> Union[int, float]:
# 0 and 150 are the upper and lower limits for the search bound.
x = Max(privacy_budget, 0, 150, dtype="int")
return x.quick_result(list(self._df["carrots_eaten"]))
Expand Down
2 changes: 1 addition & 1 deletion examples/restaurant_demo/restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import math
import statistics as s
import pandas as pd
import pandas as pd # type: ignore
from collections import defaultdict

# Assumptions:
Expand Down
2 changes: 1 addition & 1 deletion pydp/algorithms/_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math

from .._pydp import _algorithms
from .._pydp import _algorithms # type: ignore

from typing import Union, List

Expand Down
2 changes: 1 addition & 1 deletion pydp/algorithms/laplacian/_percentile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def percentile(self) -> float:
"""
percentile Gets the value that was set in the constructor.
"""
return self._MetaAlgorithm__algorithm.percentile
return self._MetaAlgorithm__algorithm.percentile # type: ignore
2 changes: 1 addition & 1 deletion pydp/distributions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .._pydp._distributions import *
from .._pydp._distributions import * # type: ignore
2 changes: 1 addition & 1 deletion pydp/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .._pydp._util import *
from .._pydp._util import * # type: ignore
4 changes: 2 additions & 2 deletions tests/base/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import pydp as dp
import pytest # type: ignore
import pydp as dp # type: ignore

# TODO: Check whether we should delete logging public binding or allow it
pytestmark = pytest.mark.skip(reason="we do not return allow user to set up logging.")
Expand Down
4 changes: 2 additions & 2 deletions tests/base/test_percentile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import pydp as dp
import pytest # type: ignore
import pydp as dp # type: ignore

# TODO: check whether to delete this test suit or update it
pytestmark = pytest.mark.skip(
Expand Down
4 changes: 2 additions & 2 deletions tests/base/test_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import pytest # type: ignore

import pydp as dp
import pydp as dp # type: ignore

# TODO: Check whether we should delete status public bindings or return status to the user
pytestmark = pytest.mark.skip(reason="we do not return status to the user.")
Expand Down