Skip to content

Commit

Permalink
PY3: used six.u to fix unicode variables in svmlight
Browse files Browse the repository at this point in the history
  • Loading branch information
raulgarreta authored and larsmans committed Mar 19, 2013
1 parent 3379504 commit 71d1a7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ nips2010_pdf/

examples/cluster/joblib
benchmarks/bench_covertype_data/

*.prefs
.pydevproject
13 changes: 7 additions & 6 deletions sklearn/datasets/svmlight_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .. import __version__
from ..externals import six
from ..utils import atleast2d_or_csr
from ..externals.six import u


def load_svmlight_file(f, n_features=None, dtype=np.float64,
Expand Down Expand Up @@ -229,18 +230,18 @@ def load_svmlight_files(files, n_features=None, dtype=np.float64,
def _dump_svmlight(X, y, f, one_based, comment, query_id):
is_sp = int(hasattr(X, "tocsr"))
if X.dtype == np.float64:
value_pattern = u"%d:%0.16e"
value_pattern = u("%d:%0.16e")
else:
value_pattern = u"%d:%f"
value_pattern = u("%d:%f")

if y.dtype.kind == 'i':
line_pattern = u"%d"
line_pattern = u("%d")
else:
line_pattern = u"%f"
line_pattern = u("%f")

if query_id is not None:
line_pattern += u" qid:%d"
line_pattern += u" %s\n"
line_pattern += u(" qid:%d")
line_pattern += u(" %s\n")

if comment:
f.write("# Generated by dump_svmlight_file from scikit-learn %s\n"
Expand Down

0 comments on commit 71d1a7c

Please sign in to comment.