Skip to content

Commit

Permalink
MAINT: Remove unused util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Jan 17, 2018
1 parent 01282af commit ea88203
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 91 deletions.
33 changes: 2 additions & 31 deletions mizani/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,15 @@
from __future__ import division

import numpy as np
import numpy.testing as npt
import pandas as pd
import pytest


from mizani.utils import (seq, fullseq, round_any, min_max, match,
precision, first_element, multitype_sort,
from mizani.utils import (round_any, min_max, match, precision,
first_element, multitype_sort,
same_log10_order_of_magnitude)


def test_seq():
result = seq(4.1, 5.2, 0.1)
npt.assert_approx_equal(result[-1], 5.2)

result = seq(1, 10, length_out=10)
npt.assert_array_equal(result, range(1, 11))

with pytest.raises(ValueError):
seq(1, 10, length_out=0)


def test_fullseq():
result = fullseq((1, 3), size=.5)
npt.assert_array_equal(result, [1, 1.5, 2, 2.5, 3])

result = fullseq((1, 3.2), size=.5)
npt.assert_array_equal(result, [1, 1.5, 2, 2.5, 3, 3.5])

result = fullseq((0.8, 3), size=.5)
npt.assert_array_equal(result, [0.5, 1, 1.5, 2, 2.5, 3])

result = fullseq((1, 3), size=.5, pad=True)
npt.assert_array_equal(result, [0.5, 1, 1.5, 2, 2.5, 3, 3.5])

result = fullseq((2, 2), size=1)
npt.assert_array_equal(result, [1.5, 2.5])


def test_round_any():
x = 4.632
assert round_any(x, 1) == 5
Expand Down
2 changes: 1 addition & 1 deletion mizani/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""
from __future__ import division
import sys
from types import FunctionType, MethodType
from types import MethodType

import numpy as np
import pandas as pd
Expand Down
60 changes: 1 addition & 59 deletions mizani/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

__all__ = ['seq', 'fullseq', 'round_any', 'min_max', 'match',
__all__ = ['round_any', 'min_max', 'match',
'precision', 'first_element', 'multitype_sort',
'is_close_to_int', 'same_log10_order_of_magnitude',
'identity'
Expand Down Expand Up @@ -40,64 +40,6 @@
])


def seq(_from=1, to=1, by=1, length_out=None):
"""
Generate regular sequences
Parameters
----------
_from : numeric
start of the sequence.
to : numeric
end of the sequence.
by : numeric
increment of the sequence.
length_out : int
length of the sequence. If a float is supplied, it
will be rounded up
Meant to be the same as Rs seq to prevent
discrepancies at the margins
"""
if length_out is not None:
if length_out <= 0:
raise ValueError(
"length_out must be greater than zero")
return np.linspace(_from, to, np.ceil(length_out))

epsilon = np.finfo(float).eps
return np.arange(_from, to*(1+epsilon), by)


def fullseq(range, size, pad=False):
"""
Generate sequence of fixed size intervals covering range.
Parameters
----------
range : array_like
Range of sequence. Must be of length 2
size : numeric
interval size
"""
from .bounds import zero_range

range = np.asarray(range)
if zero_range(range):
return range + size * np.array([-1, 1])/2

x = seq(
round_any(range[0], size, np.floor),
round_any(range[1], size, np.ceil),
size)

# Add extra bin on bottom and on top, to guarantee that
# we cover complete range of data, whether right = True/False
if pad:
x = np.hstack([np.min(x) - size, x, np.max(x) + size])
return x


def round_any(x, accuracy, f=np.round):
"""
Round to multiple of any number.
Expand Down

0 comments on commit ea88203

Please sign in to comment.