repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ageitgey/face_recognition | examples/face_recognition_knn.py | train | def train(train_dir, model_save_path=None, n_neighbors=None, knn_algo='ball_tree', verbose=False):
"""
Trains a k-nearest neighbors classifier for face recognition.
:param train_dir: directory that contains a sub-directory for each known person, with its name.
(View in source code to see train_dir ex... | python | def train(train_dir, model_save_path=None, n_neighbors=None, knn_algo='ball_tree', verbose=False):
"""
Trains a k-nearest neighbors classifier for face recognition.
:param train_dir: directory that contains a sub-directory for each known person, with its name.
(View in source code to see train_dir ex... | [
"def",
"train",
"(",
"train_dir",
",",
"model_save_path",
"=",
"None",
",",
"n_neighbors",
"=",
"None",
",",
"knn_algo",
"=",
"'ball_tree'",
",",
"verbose",
"=",
"False",
")",
":",
"X",
"=",
"[",
"]",
"y",
"=",
"[",
"]",
"# Loop through each person in the ... | Trains a k-nearest neighbors classifier for face recognition.
:param train_dir: directory that contains a sub-directory for each known person, with its name.
(View in source code to see train_dir example tree structure)
Structure:
<train_dir>/
├── <person1>/
│ ├── <somename1>.... | [
"Trains",
"a",
"k",
"-",
"nearest",
"neighbors",
"classifier",
"for",
"face",
"recognition",
"."
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/examples/face_recognition_knn.py#L46-L108 | train |
ageitgey/face_recognition | examples/face_recognition_knn.py | predict | def predict(X_img_path, knn_clf=None, model_path=None, distance_threshold=0.6):
"""
Recognizes faces in given image using a trained KNN classifier
:param X_img_path: path to image to be recognized
:param knn_clf: (optional) a knn classifier object. if not specified, model_save_path must be specified.
... | python | def predict(X_img_path, knn_clf=None, model_path=None, distance_threshold=0.6):
"""
Recognizes faces in given image using a trained KNN classifier
:param X_img_path: path to image to be recognized
:param knn_clf: (optional) a knn classifier object. if not specified, model_save_path must be specified.
... | [
"def",
"predict",
"(",
"X_img_path",
",",
"knn_clf",
"=",
"None",
",",
"model_path",
"=",
"None",
",",
"distance_threshold",
"=",
"0.6",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"X_img_path",
")",
"or",
"os",
".",
"path",
".",
"s... | Recognizes faces in given image using a trained KNN classifier
:param X_img_path: path to image to be recognized
:param knn_clf: (optional) a knn classifier object. if not specified, model_save_path must be specified.
:param model_path: (optional) path to a pickled knn classifier. if not specified, model_s... | [
"Recognizes",
"faces",
"in",
"given",
"image",
"using",
"a",
"trained",
"KNN",
"classifier"
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/examples/face_recognition_knn.py#L111-L150 | train |
ageitgey/face_recognition | examples/face_recognition_knn.py | show_prediction_labels_on_image | def show_prediction_labels_on_image(img_path, predictions):
"""
Shows the face recognition results visually.
:param img_path: path to image to be recognized
:param predictions: results of the predict function
:return:
"""
pil_image = Image.open(img_path).convert("RGB")
draw = ImageDraw.... | python | def show_prediction_labels_on_image(img_path, predictions):
"""
Shows the face recognition results visually.
:param img_path: path to image to be recognized
:param predictions: results of the predict function
:return:
"""
pil_image = Image.open(img_path).convert("RGB")
draw = ImageDraw.... | [
"def",
"show_prediction_labels_on_image",
"(",
"img_path",
",",
"predictions",
")",
":",
"pil_image",
"=",
"Image",
".",
"open",
"(",
"img_path",
")",
".",
"convert",
"(",
"\"RGB\"",
")",
"draw",
"=",
"ImageDraw",
".",
"Draw",
"(",
"pil_image",
")",
"for",
... | Shows the face recognition results visually.
:param img_path: path to image to be recognized
:param predictions: results of the predict function
:return: | [
"Shows",
"the",
"face",
"recognition",
"results",
"visually",
"."
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/examples/face_recognition_knn.py#L153-L181 | train |
ageitgey/face_recognition | face_recognition/api.py | _rect_to_css | def _rect_to_css(rect):
"""
Convert a dlib 'rect' object to a plain tuple in (top, right, bottom, left) order
:param rect: a dlib 'rect' object
:return: a plain tuple representation of the rect in (top, right, bottom, left) order
"""
return rect.top(), rect.right(), rect.bottom(), rect.left() | python | def _rect_to_css(rect):
"""
Convert a dlib 'rect' object to a plain tuple in (top, right, bottom, left) order
:param rect: a dlib 'rect' object
:return: a plain tuple representation of the rect in (top, right, bottom, left) order
"""
return rect.top(), rect.right(), rect.bottom(), rect.left() | [
"def",
"_rect_to_css",
"(",
"rect",
")",
":",
"return",
"rect",
".",
"top",
"(",
")",
",",
"rect",
".",
"right",
"(",
")",
",",
"rect",
".",
"bottom",
"(",
")",
",",
"rect",
".",
"left",
"(",
")"
] | Convert a dlib 'rect' object to a plain tuple in (top, right, bottom, left) order
:param rect: a dlib 'rect' object
:return: a plain tuple representation of the rect in (top, right, bottom, left) order | [
"Convert",
"a",
"dlib",
"rect",
"object",
"to",
"a",
"plain",
"tuple",
"in",
"(",
"top",
"right",
"bottom",
"left",
")",
"order"
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L32-L39 | train |
ageitgey/face_recognition | face_recognition/api.py | _trim_css_to_bounds | def _trim_css_to_bounds(css, image_shape):
"""
Make sure a tuple in (top, right, bottom, left) order is within the bounds of the image.
:param css: plain tuple representation of the rect in (top, right, bottom, left) order
:param image_shape: numpy shape of the image array
:return: a trimmed plain... | python | def _trim_css_to_bounds(css, image_shape):
"""
Make sure a tuple in (top, right, bottom, left) order is within the bounds of the image.
:param css: plain tuple representation of the rect in (top, right, bottom, left) order
:param image_shape: numpy shape of the image array
:return: a trimmed plain... | [
"def",
"_trim_css_to_bounds",
"(",
"css",
",",
"image_shape",
")",
":",
"return",
"max",
"(",
"css",
"[",
"0",
"]",
",",
"0",
")",
",",
"min",
"(",
"css",
"[",
"1",
"]",
",",
"image_shape",
"[",
"1",
"]",
")",
",",
"min",
"(",
"css",
"[",
"2",
... | Make sure a tuple in (top, right, bottom, left) order is within the bounds of the image.
:param css: plain tuple representation of the rect in (top, right, bottom, left) order
:param image_shape: numpy shape of the image array
:return: a trimmed plain tuple representation of the rect in (top, right, botto... | [
"Make",
"sure",
"a",
"tuple",
"in",
"(",
"top",
"right",
"bottom",
"left",
")",
"order",
"is",
"within",
"the",
"bounds",
"of",
"the",
"image",
"."
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L52-L60 | train |
ageitgey/face_recognition | face_recognition/api.py | face_distance | def face_distance(face_encodings, face_to_compare):
"""
Given a list of face encodings, compare them to a known face encoding and get a euclidean distance
for each comparison face. The distance tells you how similar the faces are.
:param faces: List of face encodings to compare
:param face_to_compa... | python | def face_distance(face_encodings, face_to_compare):
"""
Given a list of face encodings, compare them to a known face encoding and get a euclidean distance
for each comparison face. The distance tells you how similar the faces are.
:param faces: List of face encodings to compare
:param face_to_compa... | [
"def",
"face_distance",
"(",
"face_encodings",
",",
"face_to_compare",
")",
":",
"if",
"len",
"(",
"face_encodings",
")",
"==",
"0",
":",
"return",
"np",
".",
"empty",
"(",
"(",
"0",
")",
")",
"return",
"np",
".",
"linalg",
".",
"norm",
"(",
"face_enco... | Given a list of face encodings, compare them to a known face encoding and get a euclidean distance
for each comparison face. The distance tells you how similar the faces are.
:param faces: List of face encodings to compare
:param face_to_compare: A face encoding to compare against
:return: A numpy ndar... | [
"Given",
"a",
"list",
"of",
"face",
"encodings",
"compare",
"them",
"to",
"a",
"known",
"face",
"encoding",
"and",
"get",
"a",
"euclidean",
"distance",
"for",
"each",
"comparison",
"face",
".",
"The",
"distance",
"tells",
"you",
"how",
"similar",
"the",
"f... | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L63-L75 | train |
ageitgey/face_recognition | face_recognition/api.py | load_image_file | def load_image_file(file, mode='RGB'):
"""
Loads an image file (.jpg, .png, etc) into a numpy array
:param file: image file name or file object to load
:param mode: format to convert the image to. Only 'RGB' (8-bit RGB, 3 channels) and 'L' (black and white) are supported.
:return: image contents as... | python | def load_image_file(file, mode='RGB'):
"""
Loads an image file (.jpg, .png, etc) into a numpy array
:param file: image file name or file object to load
:param mode: format to convert the image to. Only 'RGB' (8-bit RGB, 3 channels) and 'L' (black and white) are supported.
:return: image contents as... | [
"def",
"load_image_file",
"(",
"file",
",",
"mode",
"=",
"'RGB'",
")",
":",
"im",
"=",
"PIL",
".",
"Image",
".",
"open",
"(",
"file",
")",
"if",
"mode",
":",
"im",
"=",
"im",
".",
"convert",
"(",
"mode",
")",
"return",
"np",
".",
"array",
"(",
... | Loads an image file (.jpg, .png, etc) into a numpy array
:param file: image file name or file object to load
:param mode: format to convert the image to. Only 'RGB' (8-bit RGB, 3 channels) and 'L' (black and white) are supported.
:return: image contents as numpy array | [
"Loads",
"an",
"image",
"file",
"(",
".",
"jpg",
".",
"png",
"etc",
")",
"into",
"a",
"numpy",
"array"
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L78-L89 | train |
ageitgey/face_recognition | face_recognition/api.py | _raw_face_locations | def _raw_face_locations(img, number_of_times_to_upsample=1, model="hog"):
"""
Returns an array of bounding boxes of human faces in a image
:param img: An image (as a numpy array)
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller face... | python | def _raw_face_locations(img, number_of_times_to_upsample=1, model="hog"):
"""
Returns an array of bounding boxes of human faces in a image
:param img: An image (as a numpy array)
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller face... | [
"def",
"_raw_face_locations",
"(",
"img",
",",
"number_of_times_to_upsample",
"=",
"1",
",",
"model",
"=",
"\"hog\"",
")",
":",
"if",
"model",
"==",
"\"cnn\"",
":",
"return",
"cnn_face_detector",
"(",
"img",
",",
"number_of_times_to_upsample",
")",
"else",
":",
... | Returns an array of bounding boxes of human faces in a image
:param img: An image (as a numpy array)
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
:param model: Which face detection model to use. "hog" is less accurate but fas... | [
"Returns",
"an",
"array",
"of",
"bounding",
"boxes",
"of",
"human",
"faces",
"in",
"a",
"image"
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L92-L105 | train |
ageitgey/face_recognition | face_recognition/api.py | face_locations | def face_locations(img, number_of_times_to_upsample=1, model="hog"):
"""
Returns an array of bounding boxes of human faces in a image
:param img: An image (as a numpy array)
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
... | python | def face_locations(img, number_of_times_to_upsample=1, model="hog"):
"""
Returns an array of bounding boxes of human faces in a image
:param img: An image (as a numpy array)
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
... | [
"def",
"face_locations",
"(",
"img",
",",
"number_of_times_to_upsample",
"=",
"1",
",",
"model",
"=",
"\"hog\"",
")",
":",
"if",
"model",
"==",
"\"cnn\"",
":",
"return",
"[",
"_trim_css_to_bounds",
"(",
"_rect_to_css",
"(",
"face",
".",
"rect",
")",
",",
"... | Returns an array of bounding boxes of human faces in a image
:param img: An image (as a numpy array)
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
:param model: Which face detection model to use. "hog" is less accurate but fas... | [
"Returns",
"an",
"array",
"of",
"bounding",
"boxes",
"of",
"human",
"faces",
"in",
"a",
"image"
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L108-L121 | train |
ageitgey/face_recognition | face_recognition/api.py | batch_face_locations | def batch_face_locations(images, number_of_times_to_upsample=1, batch_size=128):
"""
Returns an 2d array of bounding boxes of human faces in a image using the cnn face detector
If you are using a GPU, this can give you much faster results since the GPU
can process batches of images at once. If you aren'... | python | def batch_face_locations(images, number_of_times_to_upsample=1, batch_size=128):
"""
Returns an 2d array of bounding boxes of human faces in a image using the cnn face detector
If you are using a GPU, this can give you much faster results since the GPU
can process batches of images at once. If you aren'... | [
"def",
"batch_face_locations",
"(",
"images",
",",
"number_of_times_to_upsample",
"=",
"1",
",",
"batch_size",
"=",
"128",
")",
":",
"def",
"convert_cnn_detections_to_css",
"(",
"detections",
")",
":",
"return",
"[",
"_trim_css_to_bounds",
"(",
"_rect_to_css",
"(",
... | Returns an 2d array of bounding boxes of human faces in a image using the cnn face detector
If you are using a GPU, this can give you much faster results since the GPU
can process batches of images at once. If you aren't using a GPU, you don't need this function.
:param img: A list of images (each as a num... | [
"Returns",
"an",
"2d",
"array",
"of",
"bounding",
"boxes",
"of",
"human",
"faces",
"in",
"a",
"image",
"using",
"the",
"cnn",
"face",
"detector",
"If",
"you",
"are",
"using",
"a",
"GPU",
"this",
"can",
"give",
"you",
"much",
"faster",
"results",
"since",... | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L135-L151 | train |
ageitgey/face_recognition | face_recognition/api.py | face_landmarks | def face_landmarks(face_image, face_locations=None, model="large"):
"""
Given an image, returns a dict of face feature locations (eyes, nose, etc) for each face in the image
:param face_image: image to search
:param face_locations: Optionally provide a list of face locations to check.
:param model:... | python | def face_landmarks(face_image, face_locations=None, model="large"):
"""
Given an image, returns a dict of face feature locations (eyes, nose, etc) for each face in the image
:param face_image: image to search
:param face_locations: Optionally provide a list of face locations to check.
:param model:... | [
"def",
"face_landmarks",
"(",
"face_image",
",",
"face_locations",
"=",
"None",
",",
"model",
"=",
"\"large\"",
")",
":",
"landmarks",
"=",
"_raw_face_landmarks",
"(",
"face_image",
",",
"face_locations",
",",
"model",
")",
"landmarks_as_tuples",
"=",
"[",
"[",
... | Given an image, returns a dict of face feature locations (eyes, nose, etc) for each face in the image
:param face_image: image to search
:param face_locations: Optionally provide a list of face locations to check.
:param model: Optional - which model to use. "large" (default) or "small" which only returns ... | [
"Given",
"an",
"image",
"returns",
"a",
"dict",
"of",
"face",
"feature",
"locations",
"(",
"eyes",
"nose",
"etc",
")",
"for",
"each",
"face",
"in",
"the",
"image"
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L168-L200 | train |
ageitgey/face_recognition | face_recognition/api.py | face_encodings | def face_encodings(face_image, known_face_locations=None, num_jitters=1):
"""
Given an image, return the 128-dimension face encoding for each face in the image.
:param face_image: The image that contains one or more faces
:param known_face_locations: Optional - the bounding boxes of each face if you al... | python | def face_encodings(face_image, known_face_locations=None, num_jitters=1):
"""
Given an image, return the 128-dimension face encoding for each face in the image.
:param face_image: The image that contains one or more faces
:param known_face_locations: Optional - the bounding boxes of each face if you al... | [
"def",
"face_encodings",
"(",
"face_image",
",",
"known_face_locations",
"=",
"None",
",",
"num_jitters",
"=",
"1",
")",
":",
"raw_landmarks",
"=",
"_raw_face_landmarks",
"(",
"face_image",
",",
"known_face_locations",
",",
"model",
"=",
"\"small\"",
")",
"return"... | Given an image, return the 128-dimension face encoding for each face in the image.
:param face_image: The image that contains one or more faces
:param known_face_locations: Optional - the bounding boxes of each face if you already know them.
:param num_jitters: How many times to re-sample the face when cal... | [
"Given",
"an",
"image",
"return",
"the",
"128",
"-",
"dimension",
"face",
"encoding",
"for",
"each",
"face",
"in",
"the",
"image",
"."
] | c96b010c02f15e8eeb0f71308c641179ac1f19bb | https://github.com/ageitgey/face_recognition/blob/c96b010c02f15e8eeb0f71308c641179ac1f19bb/face_recognition/api.py#L203-L213 | train |
apache/spark | python/pyspark/sql/types.py | _parse_datatype_string | def _parse_datatype_string(s):
"""
Parses the given data type string to a :class:`DataType`. The data type string format equals
to :class:`DataType.simpleString`, except that top level struct type can omit
the ``struct<>`` and atomic types use ``typeName()`` as their format, e.g. use ``byte`` instead
... | python | def _parse_datatype_string(s):
"""
Parses the given data type string to a :class:`DataType`. The data type string format equals
to :class:`DataType.simpleString`, except that top level struct type can omit
the ``struct<>`` and atomic types use ``typeName()`` as their format, e.g. use ``byte`` instead
... | [
"def",
"_parse_datatype_string",
"(",
"s",
")",
":",
"sc",
"=",
"SparkContext",
".",
"_active_spark_context",
"def",
"from_ddl_schema",
"(",
"type_str",
")",
":",
"return",
"_parse_datatype_json_string",
"(",
"sc",
".",
"_jvm",
".",
"org",
".",
"apache",
".",
... | Parses the given data type string to a :class:`DataType`. The data type string format equals
to :class:`DataType.simpleString`, except that top level struct type can omit
the ``struct<>`` and atomic types use ``typeName()`` as their format, e.g. use ``byte`` instead
of ``tinyint`` for :class:`ByteType`. We ... | [
"Parses",
"the",
"given",
"data",
"type",
"string",
"to",
"a",
":",
"class",
":",
"DataType",
".",
"The",
"data",
"type",
"string",
"format",
"equals",
"to",
":",
"class",
":",
"DataType",
".",
"simpleString",
"except",
"that",
"top",
"level",
"struct",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L758-L820 | train |
apache/spark | python/pyspark/sql/types.py | _int_size_to_type | def _int_size_to_type(size):
"""
Return the Catalyst datatype from the size of integers.
"""
if size <= 8:
return ByteType
if size <= 16:
return ShortType
if size <= 32:
return IntegerType
if size <= 64:
return LongType | python | def _int_size_to_type(size):
"""
Return the Catalyst datatype from the size of integers.
"""
if size <= 8:
return ByteType
if size <= 16:
return ShortType
if size <= 32:
return IntegerType
if size <= 64:
return LongType | [
"def",
"_int_size_to_type",
"(",
"size",
")",
":",
"if",
"size",
"<=",
"8",
":",
"return",
"ByteType",
"if",
"size",
"<=",
"16",
":",
"return",
"ShortType",
"if",
"size",
"<=",
"32",
":",
"return",
"IntegerType",
"if",
"size",
"<=",
"64",
":",
"return"... | Return the Catalyst datatype from the size of integers. | [
"Return",
"the",
"Catalyst",
"datatype",
"from",
"the",
"size",
"of",
"integers",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L944-L955 | train |
apache/spark | python/pyspark/sql/types.py | _infer_type | def _infer_type(obj):
"""Infer the DataType from obj
"""
if obj is None:
return NullType()
if hasattr(obj, '__UDT__'):
return obj.__UDT__
dataType = _type_mappings.get(type(obj))
if dataType is DecimalType:
# the precision and scale of `obj` may be different from row to... | python | def _infer_type(obj):
"""Infer the DataType from obj
"""
if obj is None:
return NullType()
if hasattr(obj, '__UDT__'):
return obj.__UDT__
dataType = _type_mappings.get(type(obj))
if dataType is DecimalType:
# the precision and scale of `obj` may be different from row to... | [
"def",
"_infer_type",
"(",
"obj",
")",
":",
"if",
"obj",
"is",
"None",
":",
"return",
"NullType",
"(",
")",
"if",
"hasattr",
"(",
"obj",
",",
"'__UDT__'",
")",
":",
"return",
"obj",
".",
"__UDT__",
"dataType",
"=",
"_type_mappings",
".",
"get",
"(",
... | Infer the DataType from obj | [
"Infer",
"the",
"DataType",
"from",
"obj"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1003-L1038 | train |
apache/spark | python/pyspark/sql/types.py | _infer_schema | def _infer_schema(row, names=None):
"""Infer the schema from dict/namedtuple/object"""
if isinstance(row, dict):
items = sorted(row.items())
elif isinstance(row, (tuple, list)):
if hasattr(row, "__fields__"): # Row
items = zip(row.__fields__, tuple(row))
elif hasattr(ro... | python | def _infer_schema(row, names=None):
"""Infer the schema from dict/namedtuple/object"""
if isinstance(row, dict):
items = sorted(row.items())
elif isinstance(row, (tuple, list)):
if hasattr(row, "__fields__"): # Row
items = zip(row.__fields__, tuple(row))
elif hasattr(ro... | [
"def",
"_infer_schema",
"(",
"row",
",",
"names",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"row",
",",
"dict",
")",
":",
"items",
"=",
"sorted",
"(",
"row",
".",
"items",
"(",
")",
")",
"elif",
"isinstance",
"(",
"row",
",",
"(",
"tuple",
... | Infer the schema from dict/namedtuple/object | [
"Infer",
"the",
"schema",
"from",
"dict",
"/",
"namedtuple",
"/",
"object"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1041-L1065 | train |
apache/spark | python/pyspark/sql/types.py | _has_nulltype | def _has_nulltype(dt):
""" Return whether there is NullType in `dt` or not """
if isinstance(dt, StructType):
return any(_has_nulltype(f.dataType) for f in dt.fields)
elif isinstance(dt, ArrayType):
return _has_nulltype((dt.elementType))
elif isinstance(dt, MapType):
return _has_... | python | def _has_nulltype(dt):
""" Return whether there is NullType in `dt` or not """
if isinstance(dt, StructType):
return any(_has_nulltype(f.dataType) for f in dt.fields)
elif isinstance(dt, ArrayType):
return _has_nulltype((dt.elementType))
elif isinstance(dt, MapType):
return _has_... | [
"def",
"_has_nulltype",
"(",
"dt",
")",
":",
"if",
"isinstance",
"(",
"dt",
",",
"StructType",
")",
":",
"return",
"any",
"(",
"_has_nulltype",
"(",
"f",
".",
"dataType",
")",
"for",
"f",
"in",
"dt",
".",
"fields",
")",
"elif",
"isinstance",
"(",
"dt... | Return whether there is NullType in `dt` or not | [
"Return",
"whether",
"there",
"is",
"NullType",
"in",
"dt",
"or",
"not"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1068-L1077 | train |
apache/spark | python/pyspark/sql/types.py | _create_converter | def _create_converter(dataType):
"""Create a converter to drop the names of fields in obj """
if not _need_converter(dataType):
return lambda x: x
if isinstance(dataType, ArrayType):
conv = _create_converter(dataType.elementType)
return lambda row: [conv(v) for v in row]
elif i... | python | def _create_converter(dataType):
"""Create a converter to drop the names of fields in obj """
if not _need_converter(dataType):
return lambda x: x
if isinstance(dataType, ArrayType):
conv = _create_converter(dataType.elementType)
return lambda row: [conv(v) for v in row]
elif i... | [
"def",
"_create_converter",
"(",
"dataType",
")",
":",
"if",
"not",
"_need_converter",
"(",
"dataType",
")",
":",
"return",
"lambda",
"x",
":",
"x",
"if",
"isinstance",
"(",
"dataType",
",",
"ArrayType",
")",
":",
"conv",
"=",
"_create_converter",
"(",
"da... | Create a converter to drop the names of fields in obj | [
"Create",
"a",
"converter",
"to",
"drop",
"the",
"names",
"of",
"fields",
"in",
"obj"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1133-L1180 | train |
apache/spark | python/pyspark/sql/types.py | _make_type_verifier | def _make_type_verifier(dataType, nullable=True, name=None):
"""
Make a verifier that checks the type of obj against dataType and raises a TypeError if they do
not match.
This verifier also checks the value of obj against datatype and raises a ValueError if it's not
within the allowed range, e.g. u... | python | def _make_type_verifier(dataType, nullable=True, name=None):
"""
Make a verifier that checks the type of obj against dataType and raises a TypeError if they do
not match.
This verifier also checks the value of obj against datatype and raises a ValueError if it's not
within the allowed range, e.g. u... | [
"def",
"_make_type_verifier",
"(",
"dataType",
",",
"nullable",
"=",
"True",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"new_msg",
"=",
"lambda",
"msg",
":",
"msg",
"new_name",
"=",
"lambda",
"n",
":",
"\"field %s\"",
"%",
"n"... | Make a verifier that checks the type of obj against dataType and raises a TypeError if they do
not match.
This verifier also checks the value of obj against datatype and raises a ValueError if it's not
within the allowed range, e.g. using 128 as ByteType will overflow. Note that, Python float is
not ch... | [
"Make",
"a",
"verifier",
"that",
"checks",
"the",
"type",
"of",
"obj",
"against",
"dataType",
"and",
"raises",
"a",
"TypeError",
"if",
"they",
"do",
"not",
"match",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1202-L1391 | train |
apache/spark | python/pyspark/sql/types.py | to_arrow_type | def to_arrow_type(dt):
""" Convert Spark data type to pyarrow type
"""
import pyarrow as pa
if type(dt) == BooleanType:
arrow_type = pa.bool_()
elif type(dt) == ByteType:
arrow_type = pa.int8()
elif type(dt) == ShortType:
arrow_type = pa.int16()
elif type(dt) == Integ... | python | def to_arrow_type(dt):
""" Convert Spark data type to pyarrow type
"""
import pyarrow as pa
if type(dt) == BooleanType:
arrow_type = pa.bool_()
elif type(dt) == ByteType:
arrow_type = pa.int8()
elif type(dt) == ShortType:
arrow_type = pa.int16()
elif type(dt) == Integ... | [
"def",
"to_arrow_type",
"(",
"dt",
")",
":",
"import",
"pyarrow",
"as",
"pa",
"if",
"type",
"(",
"dt",
")",
"==",
"BooleanType",
":",
"arrow_type",
"=",
"pa",
".",
"bool_",
"(",
")",
"elif",
"type",
"(",
"dt",
")",
"==",
"ByteType",
":",
"arrow_type"... | Convert Spark data type to pyarrow type | [
"Convert",
"Spark",
"data",
"type",
"to",
"pyarrow",
"type"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1581-L1622 | train |
apache/spark | python/pyspark/sql/types.py | to_arrow_schema | def to_arrow_schema(schema):
""" Convert a schema from Spark to Arrow
"""
import pyarrow as pa
fields = [pa.field(field.name, to_arrow_type(field.dataType), nullable=field.nullable)
for field in schema]
return pa.schema(fields) | python | def to_arrow_schema(schema):
""" Convert a schema from Spark to Arrow
"""
import pyarrow as pa
fields = [pa.field(field.name, to_arrow_type(field.dataType), nullable=field.nullable)
for field in schema]
return pa.schema(fields) | [
"def",
"to_arrow_schema",
"(",
"schema",
")",
":",
"import",
"pyarrow",
"as",
"pa",
"fields",
"=",
"[",
"pa",
".",
"field",
"(",
"field",
".",
"name",
",",
"to_arrow_type",
"(",
"field",
".",
"dataType",
")",
",",
"nullable",
"=",
"field",
".",
"nullab... | Convert a schema from Spark to Arrow | [
"Convert",
"a",
"schema",
"from",
"Spark",
"to",
"Arrow"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1625-L1631 | train |
apache/spark | python/pyspark/sql/types.py | from_arrow_type | def from_arrow_type(at):
""" Convert pyarrow type to Spark data type.
"""
import pyarrow.types as types
if types.is_boolean(at):
spark_type = BooleanType()
elif types.is_int8(at):
spark_type = ByteType()
elif types.is_int16(at):
spark_type = ShortType()
elif types.is_... | python | def from_arrow_type(at):
""" Convert pyarrow type to Spark data type.
"""
import pyarrow.types as types
if types.is_boolean(at):
spark_type = BooleanType()
elif types.is_int8(at):
spark_type = ByteType()
elif types.is_int16(at):
spark_type = ShortType()
elif types.is_... | [
"def",
"from_arrow_type",
"(",
"at",
")",
":",
"import",
"pyarrow",
".",
"types",
"as",
"types",
"if",
"types",
".",
"is_boolean",
"(",
"at",
")",
":",
"spark_type",
"=",
"BooleanType",
"(",
")",
"elif",
"types",
".",
"is_int8",
"(",
"at",
")",
":",
... | Convert pyarrow type to Spark data type. | [
"Convert",
"pyarrow",
"type",
"to",
"Spark",
"data",
"type",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1634-L1674 | train |
apache/spark | python/pyspark/sql/types.py | from_arrow_schema | def from_arrow_schema(arrow_schema):
""" Convert schema from Arrow to Spark.
"""
return StructType(
[StructField(field.name, from_arrow_type(field.type), nullable=field.nullable)
for field in arrow_schema]) | python | def from_arrow_schema(arrow_schema):
""" Convert schema from Arrow to Spark.
"""
return StructType(
[StructField(field.name, from_arrow_type(field.type), nullable=field.nullable)
for field in arrow_schema]) | [
"def",
"from_arrow_schema",
"(",
"arrow_schema",
")",
":",
"return",
"StructType",
"(",
"[",
"StructField",
"(",
"field",
".",
"name",
",",
"from_arrow_type",
"(",
"field",
".",
"type",
")",
",",
"nullable",
"=",
"field",
".",
"nullable",
")",
"for",
"fiel... | Convert schema from Arrow to Spark. | [
"Convert",
"schema",
"from",
"Arrow",
"to",
"Spark",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1677-L1682 | train |
apache/spark | python/pyspark/sql/types.py | _check_series_localize_timestamps | def _check_series_localize_timestamps(s, timezone):
"""
Convert timezone aware timestamps to timezone-naive in the specified timezone or local timezone.
If the input series is not a timestamp series, then the same series is returned. If the input
series is a timestamp series, then a converted series is... | python | def _check_series_localize_timestamps(s, timezone):
"""
Convert timezone aware timestamps to timezone-naive in the specified timezone or local timezone.
If the input series is not a timestamp series, then the same series is returned. If the input
series is a timestamp series, then a converted series is... | [
"def",
"_check_series_localize_timestamps",
"(",
"s",
",",
"timezone",
")",
":",
"from",
"pyspark",
".",
"sql",
".",
"utils",
"import",
"require_minimum_pandas_version",
"require_minimum_pandas_version",
"(",
")",
"from",
"pandas",
".",
"api",
".",
"types",
"import"... | Convert timezone aware timestamps to timezone-naive in the specified timezone or local timezone.
If the input series is not a timestamp series, then the same series is returned. If the input
series is a timestamp series, then a converted series is returned.
:param s: pandas.Series
:param timezone: the... | [
"Convert",
"timezone",
"aware",
"timestamps",
"to",
"timezone",
"-",
"naive",
"in",
"the",
"specified",
"timezone",
"or",
"local",
"timezone",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1700-L1720 | train |
apache/spark | python/pyspark/sql/types.py | _check_dataframe_localize_timestamps | def _check_dataframe_localize_timestamps(pdf, timezone):
"""
Convert timezone aware timestamps to timezone-naive in the specified timezone or local timezone
:param pdf: pandas.DataFrame
:param timezone: the timezone to convert. if None then use local timezone
:return pandas.DataFrame where any time... | python | def _check_dataframe_localize_timestamps(pdf, timezone):
"""
Convert timezone aware timestamps to timezone-naive in the specified timezone or local timezone
:param pdf: pandas.DataFrame
:param timezone: the timezone to convert. if None then use local timezone
:return pandas.DataFrame where any time... | [
"def",
"_check_dataframe_localize_timestamps",
"(",
"pdf",
",",
"timezone",
")",
":",
"from",
"pyspark",
".",
"sql",
".",
"utils",
"import",
"require_minimum_pandas_version",
"require_minimum_pandas_version",
"(",
")",
"for",
"column",
",",
"series",
"in",
"pdf",
".... | Convert timezone aware timestamps to timezone-naive in the specified timezone or local timezone
:param pdf: pandas.DataFrame
:param timezone: the timezone to convert. if None then use local timezone
:return pandas.DataFrame where any timezone aware columns have been converted to tz-naive | [
"Convert",
"timezone",
"aware",
"timestamps",
"to",
"timezone",
"-",
"naive",
"in",
"the",
"specified",
"timezone",
"or",
"local",
"timezone"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1723-L1736 | train |
apache/spark | python/pyspark/sql/types.py | _check_series_convert_timestamps_internal | def _check_series_convert_timestamps_internal(s, timezone):
"""
Convert a tz-naive timestamp in the specified timezone or local timezone to UTC normalized for
Spark internal storage
:param s: a pandas.Series
:param timezone: the timezone to convert. if None then use local timezone
:return panda... | python | def _check_series_convert_timestamps_internal(s, timezone):
"""
Convert a tz-naive timestamp in the specified timezone or local timezone to UTC normalized for
Spark internal storage
:param s: a pandas.Series
:param timezone: the timezone to convert. if None then use local timezone
:return panda... | [
"def",
"_check_series_convert_timestamps_internal",
"(",
"s",
",",
"timezone",
")",
":",
"from",
"pyspark",
".",
"sql",
".",
"utils",
"import",
"require_minimum_pandas_version",
"require_minimum_pandas_version",
"(",
")",
"from",
"pandas",
".",
"api",
".",
"types",
... | Convert a tz-naive timestamp in the specified timezone or local timezone to UTC normalized for
Spark internal storage
:param s: a pandas.Series
:param timezone: the timezone to convert. if None then use local timezone
:return pandas.Series where if it is a timestamp, has been UTC normalized without a t... | [
"Convert",
"a",
"tz",
"-",
"naive",
"timestamp",
"in",
"the",
"specified",
"timezone",
"or",
"local",
"timezone",
"to",
"UTC",
"normalized",
"for",
"Spark",
"internal",
"storage"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1739-L1789 | train |
apache/spark | python/pyspark/sql/types.py | _check_series_convert_timestamps_localize | def _check_series_convert_timestamps_localize(s, from_timezone, to_timezone):
"""
Convert timestamp to timezone-naive in the specified timezone or local timezone
:param s: a pandas.Series
:param from_timezone: the timezone to convert from. if None then use local timezone
:param to_timezone: the tim... | python | def _check_series_convert_timestamps_localize(s, from_timezone, to_timezone):
"""
Convert timestamp to timezone-naive in the specified timezone or local timezone
:param s: a pandas.Series
:param from_timezone: the timezone to convert from. if None then use local timezone
:param to_timezone: the tim... | [
"def",
"_check_series_convert_timestamps_localize",
"(",
"s",
",",
"from_timezone",
",",
"to_timezone",
")",
":",
"from",
"pyspark",
".",
"sql",
".",
"utils",
"import",
"require_minimum_pandas_version",
"require_minimum_pandas_version",
"(",
")",
"import",
"pandas",
"as... | Convert timestamp to timezone-naive in the specified timezone or local timezone
:param s: a pandas.Series
:param from_timezone: the timezone to convert from. if None then use local timezone
:param to_timezone: the timezone to convert to. if None then use local timezone
:return pandas.Series where if it... | [
"Convert",
"timestamp",
"to",
"timezone",
"-",
"naive",
"in",
"the",
"specified",
"timezone",
"or",
"local",
"timezone"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1792-L1817 | train |
apache/spark | python/pyspark/sql/types.py | StructType.add | def add(self, field, data_type=None, nullable=True, metadata=None):
"""
Construct a StructType by adding new elements to it to define the schema. The method accepts
either:
a) A single parameter which is a StructField object.
b) Between 2 and 4 parameters as (name, data_... | python | def add(self, field, data_type=None, nullable=True, metadata=None):
"""
Construct a StructType by adding new elements to it to define the schema. The method accepts
either:
a) A single parameter which is a StructField object.
b) Between 2 and 4 parameters as (name, data_... | [
"def",
"add",
"(",
"self",
",",
"field",
",",
"data_type",
"=",
"None",
",",
"nullable",
"=",
"True",
",",
"metadata",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"field",
",",
"StructField",
")",
":",
"self",
".",
"fields",
".",
"append",
"(",
... | Construct a StructType by adding new elements to it to define the schema. The method accepts
either:
a) A single parameter which is a StructField object.
b) Between 2 and 4 parameters as (name, data_type, nullable (optional),
metadata(optional). The data_type parameter ma... | [
"Construct",
"a",
"StructType",
"by",
"adding",
"new",
"elements",
"to",
"it",
"to",
"define",
"the",
"schema",
".",
"The",
"method",
"accepts",
"either",
":"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L491-L537 | train |
apache/spark | python/pyspark/sql/types.py | UserDefinedType._cachedSqlType | def _cachedSqlType(cls):
"""
Cache the sqlType() into class, because it's heavy used in `toInternal`.
"""
if not hasattr(cls, "_cached_sql_type"):
cls._cached_sql_type = cls.sqlType()
return cls._cached_sql_type | python | def _cachedSqlType(cls):
"""
Cache the sqlType() into class, because it's heavy used in `toInternal`.
"""
if not hasattr(cls, "_cached_sql_type"):
cls._cached_sql_type = cls.sqlType()
return cls._cached_sql_type | [
"def",
"_cachedSqlType",
"(",
"cls",
")",
":",
"if",
"not",
"hasattr",
"(",
"cls",
",",
"\"_cached_sql_type\"",
")",
":",
"cls",
".",
"_cached_sql_type",
"=",
"cls",
".",
"sqlType",
"(",
")",
"return",
"cls",
".",
"_cached_sql_type"
] | Cache the sqlType() into class, because it's heavy used in `toInternal`. | [
"Cache",
"the",
"sqlType",
"()",
"into",
"class",
"because",
"it",
"s",
"heavy",
"used",
"in",
"toInternal",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L675-L681 | train |
apache/spark | python/pyspark/sql/types.py | Row.asDict | def asDict(self, recursive=False):
"""
Return as an dict
:param recursive: turns the nested Row as dict (default: False).
>>> Row(name="Alice", age=11).asDict() == {'name': 'Alice', 'age': 11}
True
>>> row = Row(key=1, value=Row(name='a', age=2))
>>> row.asDict(... | python | def asDict(self, recursive=False):
"""
Return as an dict
:param recursive: turns the nested Row as dict (default: False).
>>> Row(name="Alice", age=11).asDict() == {'name': 'Alice', 'age': 11}
True
>>> row = Row(key=1, value=Row(name='a', age=2))
>>> row.asDict(... | [
"def",
"asDict",
"(",
"self",
",",
"recursive",
"=",
"False",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"__fields__\"",
")",
":",
"raise",
"TypeError",
"(",
"\"Cannot convert a Row class into dict\"",
")",
"if",
"recursive",
":",
"def",
"conv",
"... | Return as an dict
:param recursive: turns the nested Row as dict (default: False).
>>> Row(name="Alice", age=11).asDict() == {'name': 'Alice', 'age': 11}
True
>>> row = Row(key=1, value=Row(name='a', age=2))
>>> row.asDict() == {'key': 1, 'value': Row(age=2, name='a')}
... | [
"Return",
"as",
"an",
"dict"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/types.py#L1463-L1492 | train |
apache/spark | python/pyspark/ml/regression.py | LinearRegressionModel.summary | def summary(self):
"""
Gets summary (e.g. residuals, mse, r-squared ) of model on
training set. An exception is thrown if
`trainingSummary is None`.
"""
if self.hasSummary:
return LinearRegressionTrainingSummary(super(LinearRegressionModel, self).summary)
... | python | def summary(self):
"""
Gets summary (e.g. residuals, mse, r-squared ) of model on
training set. An exception is thrown if
`trainingSummary is None`.
"""
if self.hasSummary:
return LinearRegressionTrainingSummary(super(LinearRegressionModel, self).summary)
... | [
"def",
"summary",
"(",
"self",
")",
":",
"if",
"self",
".",
"hasSummary",
":",
"return",
"LinearRegressionTrainingSummary",
"(",
"super",
"(",
"LinearRegressionModel",
",",
"self",
")",
".",
"summary",
")",
"else",
":",
"raise",
"RuntimeError",
"(",
"\"No trai... | Gets summary (e.g. residuals, mse, r-squared ) of model on
training set. An exception is thrown if
`trainingSummary is None`. | [
"Gets",
"summary",
"(",
"e",
".",
"g",
".",
"residuals",
"mse",
"r",
"-",
"squared",
")",
"of",
"model",
"on",
"training",
"set",
".",
"An",
"exception",
"is",
"thrown",
"if",
"trainingSummary",
"is",
"None",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/regression.py#L198-L208 | train |
apache/spark | python/pyspark/ml/regression.py | LinearRegressionModel.evaluate | def evaluate(self, dataset):
"""
Evaluates the model on a test dataset.
:param dataset:
Test dataset to evaluate model on, where dataset is an
instance of :py:class:`pyspark.sql.DataFrame`
"""
if not isinstance(dataset, DataFrame):
raise ValueErro... | python | def evaluate(self, dataset):
"""
Evaluates the model on a test dataset.
:param dataset:
Test dataset to evaluate model on, where dataset is an
instance of :py:class:`pyspark.sql.DataFrame`
"""
if not isinstance(dataset, DataFrame):
raise ValueErro... | [
"def",
"evaluate",
"(",
"self",
",",
"dataset",
")",
":",
"if",
"not",
"isinstance",
"(",
"dataset",
",",
"DataFrame",
")",
":",
"raise",
"ValueError",
"(",
"\"dataset must be a DataFrame but got %s.\"",
"%",
"type",
"(",
"dataset",
")",
")",
"java_lr_summary",
... | Evaluates the model on a test dataset.
:param dataset:
Test dataset to evaluate model on, where dataset is an
instance of :py:class:`pyspark.sql.DataFrame` | [
"Evaluates",
"the",
"model",
"on",
"a",
"test",
"dataset",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/regression.py#L211-L222 | train |
apache/spark | python/pyspark/ml/regression.py | GeneralizedLinearRegressionModel.summary | def summary(self):
"""
Gets summary (e.g. residuals, deviance, pValues) of model on
training set. An exception is thrown if
`trainingSummary is None`.
"""
if self.hasSummary:
return GeneralizedLinearRegressionTrainingSummary(
super(GeneralizedL... | python | def summary(self):
"""
Gets summary (e.g. residuals, deviance, pValues) of model on
training set. An exception is thrown if
`trainingSummary is None`.
"""
if self.hasSummary:
return GeneralizedLinearRegressionTrainingSummary(
super(GeneralizedL... | [
"def",
"summary",
"(",
"self",
")",
":",
"if",
"self",
".",
"hasSummary",
":",
"return",
"GeneralizedLinearRegressionTrainingSummary",
"(",
"super",
"(",
"GeneralizedLinearRegressionModel",
",",
"self",
")",
".",
"summary",
")",
"else",
":",
"raise",
"RuntimeError... | Gets summary (e.g. residuals, deviance, pValues) of model on
training set. An exception is thrown if
`trainingSummary is None`. | [
"Gets",
"summary",
"(",
"e",
".",
"g",
".",
"residuals",
"deviance",
"pValues",
")",
"of",
"model",
"on",
"training",
"set",
".",
"An",
"exception",
"is",
"thrown",
"if",
"trainingSummary",
"is",
"None",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/regression.py#L1679-L1690 | train |
apache/spark | python/pyspark/ml/regression.py | GeneralizedLinearRegressionModel.evaluate | def evaluate(self, dataset):
"""
Evaluates the model on a test dataset.
:param dataset:
Test dataset to evaluate model on, where dataset is an
instance of :py:class:`pyspark.sql.DataFrame`
"""
if not isinstance(dataset, DataFrame):
raise ValueErro... | python | def evaluate(self, dataset):
"""
Evaluates the model on a test dataset.
:param dataset:
Test dataset to evaluate model on, where dataset is an
instance of :py:class:`pyspark.sql.DataFrame`
"""
if not isinstance(dataset, DataFrame):
raise ValueErro... | [
"def",
"evaluate",
"(",
"self",
",",
"dataset",
")",
":",
"if",
"not",
"isinstance",
"(",
"dataset",
",",
"DataFrame",
")",
":",
"raise",
"ValueError",
"(",
"\"dataset must be a DataFrame but got %s.\"",
"%",
"type",
"(",
"dataset",
")",
")",
"java_glr_summary",... | Evaluates the model on a test dataset.
:param dataset:
Test dataset to evaluate model on, where dataset is an
instance of :py:class:`pyspark.sql.DataFrame` | [
"Evaluates",
"the",
"model",
"on",
"a",
"test",
"dataset",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/regression.py#L1693-L1704 | train |
apache/spark | python/pyspark/shuffle.py | _get_local_dirs | def _get_local_dirs(sub):
""" Get all the directories """
path = os.environ.get("SPARK_LOCAL_DIRS", "/tmp")
dirs = path.split(",")
if len(dirs) > 1:
# different order in different processes and instances
rnd = random.Random(os.getpid() + id(dirs))
random.shuffle(dirs, rnd.random)... | python | def _get_local_dirs(sub):
""" Get all the directories """
path = os.environ.get("SPARK_LOCAL_DIRS", "/tmp")
dirs = path.split(",")
if len(dirs) > 1:
# different order in different processes and instances
rnd = random.Random(os.getpid() + id(dirs))
random.shuffle(dirs, rnd.random)... | [
"def",
"_get_local_dirs",
"(",
"sub",
")",
":",
"path",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"\"SPARK_LOCAL_DIRS\"",
",",
"\"/tmp\"",
")",
"dirs",
"=",
"path",
".",
"split",
"(",
"\",\"",
")",
"if",
"len",
"(",
"dirs",
")",
">",
"1",
":",
"#... | Get all the directories | [
"Get",
"all",
"the",
"directories"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L71-L79 | train |
apache/spark | python/pyspark/shuffle.py | ExternalMerger._get_spill_dir | def _get_spill_dir(self, n):
""" Choose one directory for spill by number n """
return os.path.join(self.localdirs[n % len(self.localdirs)], str(n)) | python | def _get_spill_dir(self, n):
""" Choose one directory for spill by number n """
return os.path.join(self.localdirs[n % len(self.localdirs)], str(n)) | [
"def",
"_get_spill_dir",
"(",
"self",
",",
"n",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"localdirs",
"[",
"n",
"%",
"len",
"(",
"self",
".",
"localdirs",
")",
"]",
",",
"str",
"(",
"n",
")",
")"
] | Choose one directory for spill by number n | [
"Choose",
"one",
"directory",
"for",
"spill",
"by",
"number",
"n"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L219-L221 | train |
apache/spark | python/pyspark/shuffle.py | ExternalMerger.mergeValues | def mergeValues(self, iterator):
""" Combine the items by creator and combiner """
# speedup attribute lookup
creator, comb = self.agg.createCombiner, self.agg.mergeValue
c, data, pdata, hfun, batch = 0, self.data, self.pdata, self._partition, self.batch
limit = self.memory_limit... | python | def mergeValues(self, iterator):
""" Combine the items by creator and combiner """
# speedup attribute lookup
creator, comb = self.agg.createCombiner, self.agg.mergeValue
c, data, pdata, hfun, batch = 0, self.data, self.pdata, self._partition, self.batch
limit = self.memory_limit... | [
"def",
"mergeValues",
"(",
"self",
",",
"iterator",
")",
":",
"# speedup attribute lookup",
"creator",
",",
"comb",
"=",
"self",
".",
"agg",
".",
"createCombiner",
",",
"self",
".",
"agg",
".",
"mergeValue",
"c",
",",
"data",
",",
"pdata",
",",
"hfun",
"... | Combine the items by creator and combiner | [
"Combine",
"the",
"items",
"by",
"creator",
"and",
"combiner"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L231-L253 | train |
apache/spark | python/pyspark/shuffle.py | ExternalMerger.mergeCombiners | def mergeCombiners(self, iterator, limit=None):
""" Merge (K,V) pair by mergeCombiner """
if limit is None:
limit = self.memory_limit
# speedup attribute lookup
comb, hfun, objsize = self.agg.mergeCombiners, self._partition, self._object_size
c, data, pdata, batch = 0... | python | def mergeCombiners(self, iterator, limit=None):
""" Merge (K,V) pair by mergeCombiner """
if limit is None:
limit = self.memory_limit
# speedup attribute lookup
comb, hfun, objsize = self.agg.mergeCombiners, self._partition, self._object_size
c, data, pdata, batch = 0... | [
"def",
"mergeCombiners",
"(",
"self",
",",
"iterator",
",",
"limit",
"=",
"None",
")",
":",
"if",
"limit",
"is",
"None",
":",
"limit",
"=",
"self",
".",
"memory_limit",
"# speedup attribute lookup",
"comb",
",",
"hfun",
",",
"objsize",
"=",
"self",
".",
... | Merge (K,V) pair by mergeCombiner | [
"Merge",
"(",
"K",
"V",
")",
"pair",
"by",
"mergeCombiner"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L265-L289 | train |
apache/spark | python/pyspark/shuffle.py | ExternalMerger._spill | def _spill(self):
"""
dump already partitioned data into disks.
It will dump the data in batch for better performance.
"""
global MemoryBytesSpilled, DiskBytesSpilled
path = self._get_spill_dir(self.spills)
if not os.path.exists(path):
os.makedirs(pat... | python | def _spill(self):
"""
dump already partitioned data into disks.
It will dump the data in batch for better performance.
"""
global MemoryBytesSpilled, DiskBytesSpilled
path = self._get_spill_dir(self.spills)
if not os.path.exists(path):
os.makedirs(pat... | [
"def",
"_spill",
"(",
"self",
")",
":",
"global",
"MemoryBytesSpilled",
",",
"DiskBytesSpilled",
"path",
"=",
"self",
".",
"_get_spill_dir",
"(",
"self",
".",
"spills",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"os",
".... | dump already partitioned data into disks.
It will dump the data in batch for better performance. | [
"dump",
"already",
"partitioned",
"data",
"into",
"disks",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L291-L337 | train |
apache/spark | python/pyspark/shuffle.py | ExternalMerger.items | def items(self):
""" Return all merged items as iterator """
if not self.pdata and not self.spills:
return iter(self.data.items())
return self._external_items() | python | def items(self):
""" Return all merged items as iterator """
if not self.pdata and not self.spills:
return iter(self.data.items())
return self._external_items() | [
"def",
"items",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"pdata",
"and",
"not",
"self",
".",
"spills",
":",
"return",
"iter",
"(",
"self",
".",
"data",
".",
"items",
"(",
")",
")",
"return",
"self",
".",
"_external_items",
"(",
")"
] | Return all merged items as iterator | [
"Return",
"all",
"merged",
"items",
"as",
"iterator"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L339-L343 | train |
apache/spark | python/pyspark/shuffle.py | ExternalMerger._external_items | def _external_items(self):
""" Return all partitioned items as iterator """
assert not self.data
if any(self.pdata):
self._spill()
# disable partitioning and spilling when merge combiners from disk
self.pdata = []
try:
for i in range(self.partitio... | python | def _external_items(self):
""" Return all partitioned items as iterator """
assert not self.data
if any(self.pdata):
self._spill()
# disable partitioning and spilling when merge combiners from disk
self.pdata = []
try:
for i in range(self.partitio... | [
"def",
"_external_items",
"(",
"self",
")",
":",
"assert",
"not",
"self",
".",
"data",
"if",
"any",
"(",
"self",
".",
"pdata",
")",
":",
"self",
".",
"_spill",
"(",
")",
"# disable partitioning and spilling when merge combiners from disk",
"self",
".",
"pdata",
... | Return all partitioned items as iterator | [
"Return",
"all",
"partitioned",
"items",
"as",
"iterator"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L345-L364 | train |
apache/spark | python/pyspark/shuffle.py | ExternalMerger._recursive_merged_items | def _recursive_merged_items(self, index):
"""
merge the partitioned items and return the as iterator
If one partition can not be fit in memory, then them will be
partitioned and merged recursively.
"""
subdirs = [os.path.join(d, "parts", str(index)) for d in self.localdi... | python | def _recursive_merged_items(self, index):
"""
merge the partitioned items and return the as iterator
If one partition can not be fit in memory, then them will be
partitioned and merged recursively.
"""
subdirs = [os.path.join(d, "parts", str(index)) for d in self.localdi... | [
"def",
"_recursive_merged_items",
"(",
"self",
",",
"index",
")",
":",
"subdirs",
"=",
"[",
"os",
".",
"path",
".",
"join",
"(",
"d",
",",
"\"parts\"",
",",
"str",
"(",
"index",
")",
")",
"for",
"d",
"in",
"self",
".",
"localdirs",
"]",
"m",
"=",
... | merge the partitioned items and return the as iterator
If one partition can not be fit in memory, then them will be
partitioned and merged recursively. | [
"merge",
"the",
"partitioned",
"items",
"and",
"return",
"the",
"as",
"iterator"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L386-L409 | train |
apache/spark | python/pyspark/shuffle.py | ExternalSorter._get_path | def _get_path(self, n):
""" Choose one directory for spill by number n """
d = self.local_dirs[n % len(self.local_dirs)]
if not os.path.exists(d):
os.makedirs(d)
return os.path.join(d, str(n)) | python | def _get_path(self, n):
""" Choose one directory for spill by number n """
d = self.local_dirs[n % len(self.local_dirs)]
if not os.path.exists(d):
os.makedirs(d)
return os.path.join(d, str(n)) | [
"def",
"_get_path",
"(",
"self",
",",
"n",
")",
":",
"d",
"=",
"self",
".",
"local_dirs",
"[",
"n",
"%",
"len",
"(",
"self",
".",
"local_dirs",
")",
"]",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"d",
")",
":",
"os",
".",
"makedirs",
... | Choose one directory for spill by number n | [
"Choose",
"one",
"directory",
"for",
"spill",
"by",
"number",
"n"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L440-L445 | train |
apache/spark | python/pyspark/shuffle.py | ExternalSorter.sorted | def sorted(self, iterator, key=None, reverse=False):
"""
Sort the elements in iterator, do external sort when the memory
goes above the limit.
"""
global MemoryBytesSpilled, DiskBytesSpilled
batch, limit = 100, self._next_limit()
chunks, current_chunk = [], []
... | python | def sorted(self, iterator, key=None, reverse=False):
"""
Sort the elements in iterator, do external sort when the memory
goes above the limit.
"""
global MemoryBytesSpilled, DiskBytesSpilled
batch, limit = 100, self._next_limit()
chunks, current_chunk = [], []
... | [
"def",
"sorted",
"(",
"self",
",",
"iterator",
",",
"key",
"=",
"None",
",",
"reverse",
"=",
"False",
")",
":",
"global",
"MemoryBytesSpilled",
",",
"DiskBytesSpilled",
"batch",
",",
"limit",
"=",
"100",
",",
"self",
".",
"_next_limit",
"(",
")",
"chunks... | Sort the elements in iterator, do external sort when the memory
goes above the limit. | [
"Sort",
"the",
"elements",
"in",
"iterator",
"do",
"external",
"sort",
"when",
"the",
"memory",
"goes",
"above",
"the",
"limit",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L455-L501 | train |
apache/spark | python/pyspark/shuffle.py | ExternalList._spill | def _spill(self):
""" dump the values into disk """
global MemoryBytesSpilled, DiskBytesSpilled
if self._file is None:
self._open_file()
used_memory = get_used_memory()
pos = self._file.tell()
self._ser.dump_stream(self.values, self._file)
self.values... | python | def _spill(self):
""" dump the values into disk """
global MemoryBytesSpilled, DiskBytesSpilled
if self._file is None:
self._open_file()
used_memory = get_used_memory()
pos = self._file.tell()
self._ser.dump_stream(self.values, self._file)
self.values... | [
"def",
"_spill",
"(",
"self",
")",
":",
"global",
"MemoryBytesSpilled",
",",
"DiskBytesSpilled",
"if",
"self",
".",
"_file",
"is",
"None",
":",
"self",
".",
"_open_file",
"(",
")",
"used_memory",
"=",
"get_used_memory",
"(",
")",
"pos",
"=",
"self",
".",
... | dump the values into disk | [
"dump",
"the",
"values",
"into",
"disk"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L590-L602 | train |
apache/spark | python/pyspark/shuffle.py | ExternalGroupBy._spill | def _spill(self):
"""
dump already partitioned data into disks.
"""
global MemoryBytesSpilled, DiskBytesSpilled
path = self._get_spill_dir(self.spills)
if not os.path.exists(path):
os.makedirs(path)
used_memory = get_used_memory()
if not self.... | python | def _spill(self):
"""
dump already partitioned data into disks.
"""
global MemoryBytesSpilled, DiskBytesSpilled
path = self._get_spill_dir(self.spills)
if not os.path.exists(path):
os.makedirs(path)
used_memory = get_used_memory()
if not self.... | [
"def",
"_spill",
"(",
"self",
")",
":",
"global",
"MemoryBytesSpilled",
",",
"DiskBytesSpilled",
"path",
"=",
"self",
".",
"_get_spill_dir",
"(",
"self",
".",
"spills",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"os",
".... | dump already partitioned data into disks. | [
"dump",
"already",
"partitioned",
"data",
"into",
"disks",
"."
] | 618d6bff71073c8c93501ab7392c3cc579730f0b | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/shuffle.py#L709-L766 | train |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 21