Skip to content

Commit

Permalink
redirect backwards comp
Browse files Browse the repository at this point in the history
  • Loading branch information
flennerhag committed Mar 14, 2017
1 parent dab741d commit 9341850
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
9 changes: 7 additions & 2 deletions mlens/ensemble/tests/test_stacking_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"""

from __future__ import division, print_function, with_statement
from contextlib import redirect_stderr
import os

import numpy as np
from pandas import DataFrame
Expand All @@ -26,6 +24,13 @@

import warnings

import os
try:
from contextlib import redirect_stderr
except ImportError:
from mlens.externals.fixes import redirect as redirect_stderr


# Training data
np.random.seed(100)
X = np.random.random((1000, 10))
Expand Down
22 changes: 22 additions & 0 deletions mlens/externals/fixes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""ML-ENSEMBLE
Collection of simpler fixes occassionally necessary for backwards
compatibility.
"""

import sys
from contextlib import contextmanager


@contextmanager
def redirect(target, file=sys.stderr):
"""Replication of ``redirect_stderr`` or ``redirect_stdout``.
:source: http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python/22434262#22434262
"""
original, file = file, target

try:
yield target
finally:
file = original
9 changes: 7 additions & 2 deletions mlens/model_selection/tests/test_model_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"""

from __future__ import division, print_function
from contextlib import redirect_stderr
import os

import numpy as np

Expand All @@ -22,6 +20,13 @@
import warnings
import subprocess

import os
try:
from contextlib import redirect_stderr
except ImportError:
from mlens.externals.fixes import redirect as redirect_stderr


# training data
np.random.seed(100)
X = np.random.random((1000, 10))
Expand Down
9 changes: 7 additions & 2 deletions mlens/preprocessing/tests/test_feature_engineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"""

from __future__ import division, print_function
from contextlib import redirect_stderr
import os

import numpy as np

Expand All @@ -23,6 +21,13 @@

import warnings

import os
try:
from contextlib import redirect_stderr
except ImportError:
from mlens.externals.fixes import redirect as redirect_stderr


SEED = 100
np.random.seed(SEED)

Expand Down

0 comments on commit 9341850

Please sign in to comment.