Esempio n. 1
0
 def _most_recent_convictions(recent_convictions) -> Optional[Charge]:
     recent_convictions.sort(key=lambda charge: charge.disposition.date, reverse=True)
     newer, older = take(2, padnone(recent_convictions))
     if newer and "violation" in newer.level.lower():
         return older
     else:
         return newer
 def _most_recent_convictions(recent_convictions):
     recent_convictions.sort(key=lambda charge: charge.disposition.date,
                             reverse=True)
     first, second, third = take(3, padnone(recent_convictions))
     if first and "violation" in first.level.lower():
         return second, third
     elif second and "violation" in second.level.lower():
         return first, third
     else:
         return first, second
Esempio n. 3
0
def plot_dataframe(axs,
                   df: pd.DataFrame,
                   x: Optional = None,
                   y: Optional[Iterable] = None,
                   style: Optional[Iterable] = None,
                   stacked=False,
                   kind="line"):
    # for some reason df.plot() completely ruins datetime xaxis so no other formatter works
    # reinvent the wheel...
    if x is None:
        xvals = df.index.values
    elif isinstance(x, str):
        xvals = df[x].values
    else:
        xvals = x
    if y is None:
        yvals = df
    else:
        yvals = df.loc[:, y]
    if style is None:
        style = []
    if stacked:
        yvals_original = yvals.copy()
        yvals = yvals.cumsum(axis=1)
    if kind == "bar":
        styler = iter(
            cycler.cycler(hatch=[None, "///", "..."]) *
            mpl.rcParams["axes.prop_cycle"])
    cols = yvals.columns
    styletup = [(st, ) if st else ()
                for st in islice(padnone(iter(style)), len(cols))]
    for st, ci in zip(styletup, cols):
        if kind == "line":
            axs.plot(xvals, yvals[ci], *st, label=ci)
        elif kind == "bar":
            if stacked:
                bot = (yvals[ci] - yvals_original[ci]).to_numpy()
                bot[np.isnan(bot)] = 0.0
                what = dict(height=yvals_original[ci], bottom=bot)
            else:
                what = dict(height=yvals[ci])
            axs.bar(xvals,
                    **what,
                    linewidth=0,
                    width=-1.0,
                    align="edge",
                    **next(styler),
                    label=ci)
    axs.legend()
Esempio n. 4
0
 def test_happy_path(self):
     """wrapper iterator should return None indefinitely"""
     r = range(2)
     p = mi.padnone(r)
     self.assertEqual([0, 1, None, None], [next(p) for _ in range(4)])
Esempio n. 5
0
 def test_happy_path(self):
     """wrapper iterator should return None indefinitely"""
     r = range(2)
     p = mi.padnone(r)
     self.assertEqual([0, 1, None, None], [next(p) for _ in range(4)])