Skip to content

Commit

Permalink
Add pydocstyle for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pvk-developer committed Oct 4, 2021
1 parent 8794417 commit 208a62f
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def lint(c):
c.run('flake8 rdt')
c.run('pydocstyle rdt')
c.run('flake8 tests --ignore=D')
c.run('pydocstyle tests')
c.run('isort -c --recursive rdt tests')
c.run('pylint rdt tests/performance --rcfile=setup.cfg')

Expand Down
4 changes: 3 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""RDT test module."""


def safe_compare_dataframes(first, second):
"""Compare two dataframes even if they have NaN values.
Expand All @@ -8,7 +11,6 @@ def safe_compare_dataframes(first, second):
Returns:
bool
"""

if first.isnull().all().all():
return first.equals(second)

Expand Down
1 change: 1 addition & 0 deletions tests/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def generate(num_rows):
Args:
num_rows (int):
Number of rows to generate.
Returns:
numpy.ndarray of size ``num_rows``
"""
Expand Down
7 changes: 6 additions & 1 deletion tests/datasets/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RandomBooleanNaNsGenerator(BooleanGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
percent_null = np.random.randint(MIN_PERCENT, MAX_PERCENT_NULL)
percent_true = (100 - percent_null) / 2
percent_false = 100 - percent_true - percent_null
Expand All @@ -52,6 +53,7 @@ class RandomSkewedBooleanGenerator(BooleanGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
percent_true = np.random.randint(MIN_PERCENT, 100 - MIN_PERCENT)

return np.random.choice(
Expand All @@ -66,6 +68,7 @@ class RandomSkewedBooleanNaNsGenerator(BooleanGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
percent_null = np.random.randint(MIN_PERCENT, MAX_PERCENT_NULL)
percent_true = np.random.randint(MIN_PERCENT, 100 - percent_null - MIN_PERCENT)
percent_false = 100 - percent_null - percent_true
Expand All @@ -78,10 +81,11 @@ def generate(num_rows):


class ConstantBooleanGenerator(BooleanGenerator):
"""Generator that creates a constant array with either True or False"""
"""Generator that creates a constant array with either True or False."""

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
constant = np.random.choice([True, False])
return np.full(num_rows, constant)

Expand All @@ -91,6 +95,7 @@ class ConstantBooleanNaNsGenerator(BooleanGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
constant = np.random.choice([True, False])
percent_null = np.random.randint(MIN_PERCENT, MAX_PERCENT_NULL)

Expand Down
14 changes: 14 additions & 0 deletions tests/datasets/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RandomIntegerGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
categories = [1, 2, 3, 4, 5]
return np.random.choice(a=categories, size=num_rows)

Expand All @@ -27,6 +28,7 @@ class RandomIntegerNaNsGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(RandomIntegerGenerator.generate(num_rows).astype(np.float))


Expand All @@ -35,6 +37,7 @@ class RandomStringGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
categories = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve']
return np.random.choice(a=categories, size=num_rows)

Expand All @@ -44,6 +47,7 @@ class RandomStringNaNsGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(RandomStringGenerator.generate(num_rows).astype('O'))


Expand All @@ -55,6 +59,7 @@ class RandomMixedGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
cat_size = 5
categories = np.hstack([
cat.astype('O') for cat in [
Expand All @@ -77,6 +82,7 @@ class RandomMixedNaNsGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
array = RandomMixedGenerator.generate(num_rows)

length = len(array)
Expand All @@ -93,6 +99,7 @@ class SingleIntegerGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
constant = np.random.randint(0, 100)
return np.full(num_rows, constant)

Expand All @@ -102,6 +109,7 @@ class SingleIntegerNaNsGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(SingleIntegerGenerator.generate(num_rows).astype(np.float))


Expand All @@ -110,6 +118,7 @@ class SingleStringGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
constant = 'A'
return np.full(num_rows, constant)

Expand All @@ -119,6 +128,7 @@ class SingleStringNaNsGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(SingleStringGenerator.generate(num_rows).astype('O'))


Expand All @@ -127,6 +137,7 @@ class UniqueIntegerGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return np.arange(num_rows)


Expand All @@ -135,6 +146,7 @@ class UniqueIntegerNaNsGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(UniqueIntegerGenerator.generate(num_rows))


Expand All @@ -143,6 +155,7 @@ class UniqueStringGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return np.arange(num_rows).astype(str)


Expand All @@ -151,4 +164,5 @@ class UniqueStringNaNsGenerator(CategoricalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(UniqueStringGenerator.generate(num_rows).astype('O'))
20 changes: 13 additions & 7 deletions tests/datasets/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,75 @@


class DatetimeGenerator(BaseDatasetGenerator):
"""Base class for generators that generate datatime data"""
"""Base class for generators that generate datatime data."""

DATA_TYPE = 'datetime'


class RandomGapDatetimeGenerator(DatetimeGenerator):
"""Generator that creates dates with random gaps between them"""
"""Generator that creates dates with random gaps between them."""

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
today = datetime.datetime.today()
delta = datetime.timedelta(days=1)
dates = [(np.random.random() * delta + today) for i in range(num_rows)]
return np.array(dates, dtype='datetime64')


class RandomGapSecondsDatetimeGenerator(DatetimeGenerator):
"""Generator that creates dates with random gaps of seconds between them"""
"""Generator that creates dates with random gaps of seconds between them."""

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
today = datetime.datetime.today()
delta = datetime.timedelta(seconds=1)
dates = [(np.random.random() * delta + today) for i in range(num_rows)]
return np.array(dates, dtype='datetime64')


class RandomGapDatetimeNaNsGenerator(DatetimeGenerator):
"""Generator that creates dates with random gaps and NaNs"""
"""Generator that creates dates with random gaps and NaNs."""

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
dates = RandomGapDatetimeGenerator.generate(num_rows)
return add_nans(dates.astype('O'))


class EqualGapHoursDatetimeGenerator(DatetimeGenerator):
"""Generator that creates dates with hour gaps between them"""
"""Generator that creates dates with hour gaps between them."""

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
today = datetime.datetime.today()
delta = datetime.timedelta
dates = [delta(hours=i) + today for i in range(num_rows)]
return np.array(dates, dtype='datetime64')


class EqualGapDaysDatetimeGenerator(DatetimeGenerator):
"""Generator that creates dates with 1 day gaps between them"""
"""Generator that creates dates with 1 day gaps between them."""

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
today = datetime.datetime.today()
delta = datetime.timedelta
dates = [delta(i) + today for i in range(num_rows)]
return np.array(dates, dtype='datetime64')


class EqualGapWeeksDatetimeGenerator(DatetimeGenerator):
"""Generator that creates dates with 1 week gaps between them"""
"""Generator that creates dates with 1 week gaps between them."""

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
today = datetime.datetime.today()
delta = datetime.timedelta
dates = [delta(weeks=i) + today for i in range(num_rows)]
Expand Down
10 changes: 10 additions & 0 deletions tests/datasets/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RandomIntegerGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
ii32 = np.iinfo(np.int32)
return np.random.randint(ii32.min, ii32.max, num_rows)

Expand All @@ -26,6 +27,7 @@ class RandomIntegerNaNsGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(RandomIntegerGenerator.generate(num_rows).astype(np.float))


Expand All @@ -34,6 +36,7 @@ class ConstantIntegerGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
ii32 = np.iinfo(np.int32)
constant = np.random.randint(ii32.min, ii32.max)
return np.full(num_rows, constant)
Expand All @@ -44,6 +47,7 @@ class ConstantIntegerNaNsGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(ConstantIntegerGenerator.generate(num_rows).astype(np.float))


Expand All @@ -52,6 +56,7 @@ class AlmostConstantIntegerGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
ii32 = np.iinfo(np.int32)
values = np.random.randint(ii32.min, ii32.max, size=2)
additional_values = np.full(num_rows - 2, values[1])
Expand All @@ -65,6 +70,7 @@ class AlmostConstantIntegerNaNsGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
ii32 = np.iinfo(np.int32)
values = np.random.randint(ii32.min, ii32.max, size=2)
additional_values = np.full(num_rows - 2, values[1]).astype(np.float)
Expand All @@ -78,6 +84,7 @@ class NormalGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return np.random.normal(size=num_rows)


Expand All @@ -86,6 +93,7 @@ class NormalNaNsGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(NormalGenerator.generate(num_rows))


Expand All @@ -94,6 +102,7 @@ class BigNormalGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return np.random.normal(scale=1e10, size=num_rows)


Expand All @@ -102,4 +111,5 @@ class BigNormalNaNsGenerator(NumericalGenerator):

@staticmethod
def generate(num_rows):
"""Generate a ``num_rows`` number of rows."""
return add_nans(BigNormalGenerator.generate(num_rows))
1 change: 1 addition & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""RDT integration testing package."""
1 change: 1 addition & 0 deletions tests/integration/transformers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""RDT transformers integration testing package."""
1 change: 1 addition & 0 deletions tests/performance/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""RDT performance testing package."""
1 change: 1 addition & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""RDT unit testing package."""
1 change: 1 addition & 0 deletions tests/unit/transformers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""RDT transformers unit testing package."""

0 comments on commit 208a62f

Please sign in to comment.