8000 MNT Simplify creation of pickle path (#15237) · jeremiedbb/scikit-learn@5c9f090 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c9f090

Browse files
sbehrenthomasjpfan
authored andcommitted
MNT Simplify creation of pickle path (scikit-learn#15237)
1 parent 0c9a063 commit 5c9f090

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

sklearn/datasets/base.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# License: BSD 3 clause
99
import os
1010
import csv
11-
import sys
1211
import shutil
1312
import warnings
1413
from collections import namedtuple
@@ -847,30 +846,18 @@ def load_sample_image(image_name):
847846

848847

849848
def _pkl_filepath(*args, **kwargs):
850-
"""Ensure different filenames for Python 2 and Python 3 pickles
849+
"""Return filename for Python 3 pickles
851850
852-
An object pickled under Python 3 cannot be loaded under Python 2. An object
853-
pickled under Python 2 can sometimes not be loaded correctly under Python 3
854-
because some Python 2 strings are decoded as Python 3 strings which can be
855-
problematic for objects that use Python 2 strings as byte buffers for
856-
numerical data instead of "real" strings.
851+
args[-1] is expected to be the ".pkl" filename. For compatibility with
852+
older scikit-learn versions, a suffix is inserted before the extension.
857853
858-
Therefore, dataset loaders in scikit-learn use different files for pickles
859-
manages by Python 2 and Python 3 in the same SCIKIT_LEARN_DATA folder so as
860-
to avoid conflicts.
861-
862-
args[-1] is expected to be the ".pkl" filename. Under Python 3, a suffix is
863-
inserted before the extension to s
864-
865-
_pkl_filepath('/path/to/folder', 'filename.pkl') returns:
866-
- /path/to/folder/filename.pkl under Python 2
867-
- /path/to/folder/filename_py3.pkl under Python 3+
854+
_pkl_filepath('/path/to/folder', 'filename.pkl') returns
855+
'/path/to/folder/filename_py3.pkl'
868856
869857
"""
870858
py3_suffix = kwargs.get("py3_suffix", "_py3")
871859
basename, ext = splitext(args[-1])
872-
if sys.version_info[0] >= 3:
873-
basename += py3_suffix
860+
basename += py3_suffix
874861
new_args = args[:-1] + (basename + ext,)
875862
return join(*new_args)
876863

0 commit comments

Comments
 (0)
0