uid
stringlengths
24
24
split
stringclasses
1 value
category
stringclasses
2 values
content
stringlengths
5
482k
signature
stringlengths
1
14k
suffix
stringlengths
1
482k
prefix
stringlengths
9
14k
prefix_token_count
int64
3
5.01k
prefix_token_budget
int64
64
256
element_token_count
int64
1
292k
signature_token_count
int64
1
5.01k
prefix_context_token_count
int64
0
255
repo
stringlengths
7
112
path
stringlengths
4
208
language
stringclasses
1 value
name
stringlengths
1
218
qualname
stringlengths
1
218
start_line
int64
1
26.7k
end_line
int64
1
26.7k
signature_start_line
int64
1
26.7k
signature_end_line
int64
1
26.7k
source_hash
stringlengths
40
40
source_dataset
stringclasses
1 value
source_split
stringclasses
1 value
594a8814aa7638bf4cb27a11
train
function
@pytest.mark.skip def test_division_by_zero(create_drop_test_schema_fixture: cursor): cur = create_drop_test_schema_fixture cur.execute('create table schema_name.table_name(id integer, test integer)') with pytest.raises(DivisionByZero) as e: cur.execute("insert into schema_name.table_name (id, test...
@pytest.mark.skip def test_division_by_zero(create_drop_test_schema_fixture: cursor):
cur = create_drop_test_schema_fixture cur.execute('create table schema_name.table_name(id integer, test integer)') with pytest.raises(DivisionByZero) as e: cur.execute("insert into schema_name.table_name (id, test) values (%s, 1/0)", (1,)) assert e.value.pgcode == DIVISION_BY_ZERO
cur.execute("insert into schema_name.table_name (id, test) values (%s, %s)", (1, 'test_string_not_int')) assert e.value.pgcode == MOST_SPECIFIC_TYPE_MISMATCH @pytest.mark.skip def test_division_by_zero(create_drop_test_schema_fixture: cursor):
64
64
96
18
45
AndrewBregger/database
tests/functional/test_error_codes.py
Python
test_division_by_zero
test_division_by_zero
59
66
59
60
8b8a6ae63c140b6ebfe701983507ec6804550154
bigcode/the-stack
train
0f9da0e8314cecd38b74cc7f
train
function
def test_numeric_constraint_violations(create_drop_test_schema_fixture: cursor): cur = create_drop_test_schema_fixture cur.execute('create table schema_name.table_name(si_col smallint, i_col integer, bi_col bigint);') args = [(-32768, -2147483648, -9223372036854775808), (32767, 2147483647, 92233...
def test_numeric_constraint_violations(create_drop_test_schema_fixture: cursor):
cur = create_drop_test_schema_fixture cur.execute('create table schema_name.table_name(si_col smallint, i_col integer, bi_col bigint);') args = [(-32768, -2147483648, -9223372036854775808), (32767, 2147483647, 9223372036854775807)] cur.executemany('insert into schema_name.table_name values (...
psycopg import cursor from psycopg2.errors import (NumericValueOutOfRange, NullValueNotAllowed, MostSpecificTypeMismatch, DivisionByZero) # all imports from errors are OK if you can find such exception class in docs # >>> https://www.psycopg.org/docs/errors.html from psycopg2.errorcodes import * from fixtures import ...
102
102
343
15
86
AndrewBregger/database
tests/functional/test_error_codes.py
Python
test_numeric_constraint_violations
test_numeric_constraint_violations
13
33
13
13
b5bef729daa9a974694f52184f18b6ef57d7188f
bigcode/the-stack
train
b933f531920056550d374539
train
function
def _get_struct_3I(): global _struct_3I if _struct_3I is None: _struct_3I = struct.Struct("<3I") return _struct_3I
def _get_struct_3I():
global _struct_3I if _struct_3I is None: _struct_3I = struct.Struct("<3I") return _struct_3I
_struct_iB = None def _get_struct_iB(): global _struct_iB if _struct_iB is None: _struct_iB = struct.Struct("<iB") return _struct_iB _struct_3I = None def _get_struct_3I():
64
64
47
8
55
Roboy/roboy_controlled_node_fpga
opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/msg/_TestRequestActionResult.py
Python
_get_struct_3I
_get_struct_3I
325
329
325
325
9c95827b70581032c875cafeefcea847b1166539
bigcode/the-stack
train
ecb7a357ab59cc7cc2035a91
train
function
def _get_struct_2I(): global _struct_2I if _struct_2I is None: _struct_2I = struct.Struct("<2I") return _struct_2I
def _get_struct_2I():
global _struct_2I if _struct_2I is None: _struct_2I = struct.Struct("<2I") return _struct_2I
return _struct_3I _struct_B = None def _get_struct_B(): global _struct_B if _struct_B is None: _struct_B = struct.Struct("<B") return _struct_B _struct_2I = None def _get_struct_2I():
64
64
47
8
55
Roboy/roboy_controlled_node_fpga
opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/msg/_TestRequestActionResult.py
Python
_get_struct_2I
_get_struct_2I
337
341
337
337
96fad3bf2b655934bd086b999f03620a34516698
bigcode/the-stack
train
6b78010399617b2a6bb1553d
train
class
class TestRequestActionResult(genpy.Message): _md5sum = "0476d1fdf437a3a6e7d6d0e9f5561298" _type = "actionlib/TestRequestActionResult" _has_header = True #flag to mark the presence of a Header object _full_text = """# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== Header header actionlib_...
class TestRequestActionResult(genpy.Message):
_md5sum = "0476d1fdf437a3a6e7d6d0e9f5561298" _type = "actionlib/TestRequestActionResult" _has_header = True #flag to mark the presence of a Header object _full_text = """# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== Header header actionlib_msgs/GoalStatus status TestRequestResult resul...
# This Python file uses the following encoding: utf-8 """autogenerated by genpy from actionlib/TestRequestActionResult.msg. Do not edit.""" import sys python3 = True if sys.hexversion > 0x03000000 else False import genpy import struct import actionlib.msg import genpy import actionlib_msgs.msg import std_msgs.msg clas...
89
256
2,967
9
79
Roboy/roboy_controlled_node_fpga
opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/msg/_TestRequestActionResult.py
Python
TestRequestActionResult
TestRequestActionResult
13
312
13
13
eff92fc4984ff3f080ea7511ca9b9ae31e66a9e9
bigcode/the-stack
train
70d0f20cff49a502610594ac
train
function
def _get_struct_B(): global _struct_B if _struct_B is None: _struct_B = struct.Struct("<B") return _struct_B
def _get_struct_B():
global _struct_B if _struct_B is None: _struct_B = struct.Struct("<B") return _struct_B
_3I = None def _get_struct_3I(): global _struct_3I if _struct_3I is None: _struct_3I = struct.Struct("<3I") return _struct_3I _struct_B = None def _get_struct_B():
64
64
36
6
57
Roboy/roboy_controlled_node_fpga
opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/msg/_TestRequestActionResult.py
Python
_get_struct_B
_get_struct_B
331
335
331
331
9de85bfa62bfced463ffaf8a2337cb3b22e8e90f
bigcode/the-stack
train
4652b36e5efd836987208d90
train
function
def _get_struct_iB(): global _struct_iB if _struct_iB is None: _struct_iB = struct.Struct("<iB") return _struct_iB
def _get_struct_iB():
global _struct_iB if _struct_iB is None: _struct_iB = struct.Struct("<iB") return _struct_iB
self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I def _get_struct_I(): global _struct_I return _struct_I _struct_iB = None def _get_struct_iB():
64
64
42
7
56
Roboy/roboy_controlled_node_fpga
opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/msg/_TestRequestActionResult.py
Python
_get_struct_iB
_get_struct_iB
319
323
319
319
4485c768421a0adadf42140c87244a606ce41c96
bigcode/the-stack
train
5e108d36cdd5aacdeb02a833
train
function
def _get_struct_I(): global _struct_I return _struct_I
def _get_struct_I():
global _struct_I return _struct_I
_iB().unpack(str[start:end]) self.result.is_simple_server = bool(self.result.is_simple_server) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill _struct_I = genpy.struct_I def _get_struct_I():
64
64
18
6
57
Roboy/roboy_controlled_node_fpga
opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/msg/_TestRequestActionResult.py
Python
_get_struct_I
_get_struct_I
315
317
315
315
72b073a01b474fd54b1e1016eaaaa07c0526f426
bigcode/the-stack
train
4a929888b74d4080be52c468
train
function
@silent async def smartpurge(func): orig = await ctx.msg.get_reply_message() async for msg in client.iter_messages(ctx.msg.chat_id): if func(msg): await msg.delete() if msg == orig: break
@silent async def smartpurge(func):
orig = await ctx.msg.get_reply_message() async for msg in client.iter_messages(ctx.msg.chat_id): if func(msg): await msg.delete() if msg == orig: break
# Filter and delete messages up to given @silent async def smartpurge(func):
19
64
52
10
8
liferooter/tgpy-snippets
functions/smartpurge.py
Python
smartpurge
smartpurge
3
10
3
4
823dd564b0acc3e44e6e93f6583f9ac0b6d1acf0
bigcode/the-stack
train
b340cf4a3897100eee0152a9
train
class
class Map: def __init__(self, file_name): self.tileset = None self.layers = [] self.layer_size = (0, 0,) # Load the map for the correct level map_file = open(file_name) layer_will_be_solid = False in_layer = False for line in map_file.read().splitli...
class Map:
def __init__(self, file_name): self.tileset = None self.layers = [] self.layer_size = (0, 0,) # Load the map for the correct level map_file = open(file_name) layer_will_be_solid = False in_layer = False for line in map_file.read().splitlines(): ...
""" Map class for playable and useable maps. """ import os import pygame from src.config import CONFIG from src.gfx.tileset import Tileset from src.gfx.map_layer import MapLayer import lib.PAdLib.occluder as occluder import lib.PAdLib.shadow as shadow class Map:
68
256
1,048
3
64
MartinKondor/leap-of-time
src/gfx/map.py
Python
Map
Map
16
134
16
17
20cb880e2c5f474af311cc6503056c2b19a0296c
bigcode/the-stack
train
3462f75ca59b61d4e241f823
train
class
class Default_Values(object): """ Class for parsing default values. """ register_names = [] def __init__(self, default_values_file, **kwargs): self.default_values_file = default_values_file def parse(self): with open(self.default_values_file) as f: values_dict = ...
class Default_Values(object):
""" Class for parsing default values. """ register_names = [] def __init__(self, default_values_file, **kwargs): self.default_values_file = default_values_file def parse(self): with open(self.default_values_file) as f: values_dict = json.load(f) return va...
import json class Default_Values(object):
9
64
75
6
2
daniel-thom/ditto
ditto/default_values/default_values_json.py
Python
Default_Values
Default_Values
4
19
4
4
1aeb64f524280645d44557330d4757f515e899a8
bigcode/the-stack
train
7d1e5b84de0e191a22bc15b0
train
function
def test_strtree_threaded_query(): ## Create data polygons = pygeos.polygons(np.random.randn(1000, 3, 2)) # needs to be big enough to trigger the segfault N = 100_000 points = pygeos.points(4 * np.random.random(N) - 2, 4 * np.random.random(N) - 2) ## Slice parts of the arrays -> 4x4 => 16 combi...
def test_strtree_threaded_query(): ## Create data
polygons = pygeos.polygons(np.random.randn(1000, 3, 2)) # needs to be big enough to trigger the segfault N = 100_000 points = pygeos.points(4 * np.random.random(N) - 2, 4 * np.random.random(N) - 2) ## Slice parts of the arrays -> 4x4 => 16 combinations n = int(len(polygons) / 4) polygons_pa...
geos.points(0, 0), [0.0]), (pygeos.points(0.5, 0.5), [0.7071, 0.7071])], ) def test_nearest_all_return_distance(tree, geometry, expected): assert_array_equal( np.round(tree.nearest_all(geometry, return_distance=True)[1], 4), expected ) def test_strtree_threaded_query(): ## Create data
97
97
326
13
84
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_strtree_threaded_query
test_strtree_threaded_query
1,490
1,529
1,490
1,491
4f6884fa54851994484d5cd798ed1653afd37ac2
bigcode/the-stack
train
6395280a016202c7850970e6
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line ([pygeos.points(0, 0)], [[0], [0]]), ([pygeos.points(0.5, 0.5)], [[0], [0]]), # point within envelope of first line but does not intersect ([pygeos.points(0, 0.5)], [[], []]), # point a...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line ([pygeos.points(0, 0)], [[0], [0]]), ([pygeos.points(0.5, 0.5)], [[0], [0]]), # point within envelope of first line but does not intersect ([pygeos.points(0, 0.5)], [[], []]), # point a...
assert_array_equal(line_tree.query_bulk(geometry, predicate="intersects"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line ([pygeos.points(0, 0)], [[0], [0]]), ([pygeos.points(0.5, 0.5)], [[0], [0]]), # point within envelope of first line but does not intersect ([pygeos.points(0, 0.5)], [[], []]), # point a...
438
136
456
438
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_intersects_lines
test_query_bulk_intersects_lines
1,120
1,148
1,120
1,147
861a71e6c12eba4c4bd1ce2786046f50f02e0b1a
bigcode/the-stack
train
411643da036d7ea702bd30bc
train
function
def test_geometries_property(): arr = np.array([point]) tree = pygeos.STRtree(arr) assert arr is tree.geometries
def test_geometries_property():
arr = np.array([point]) tree = pygeos.STRtree(arr) assert arr is tree.geometries
(10), np.arange(10)) tree = pygeos.STRtree(arr) # Dereference geometries arr[:] = None import gc gc.collect() # Still it does not lead to a segfault tree.query(point) def test_geometries_property():
64
64
35
7
57
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_geometries_property
test_geometries_property
102
105
102
102
c65fa7c98e6e799ba326803a27d951fd771413e1
bigcode/the-stack
train
cdccf7b58b1120bea60f7c9a
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.25, 0.25), [[0], [0]]), (pygeos.points(0.75, 0.75), [[0], [1]]), (pygeos.points(1, 1), [[0], [1]]), ([pygeos.points(1, 1), pygeos.points(0, ...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.25, 0.25), [[0], [0]]), (pygeos.points(0.75, 0.75), [[0], [1]]), (pygeos.points(1, 1), [[0], [1]]), ([pygeos.points(1, 1), pygeos.points(0, ...
assert_array_equal(tree.nearest(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.25, 0.25), [[0], [0]]), (pygeos.points(0.75, 0.75), [[0], [1]]), (pygeos.points(1, 1), [[0], [1]]), ([pygeos.points(1, 1), pygeos.points(0, ...
392
121
404
392
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_points
test_nearest_points
1,207
1,227
1,207
1,226
e7020679102a2af1d6c1a5f172e8ad8afcae92d2
bigcode/the-stack
train
dec5d120809efdb220397be8
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_empty_tree(): tree = pygeos.STRtree([]) assert_array_equal(tree.nearest(point), [[], []])
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_empty_tree():
tree = pygeos.STRtree([]) assert_array_equal(tree.nearest(point), [[], []])
_polygons(poly_tree, geometry, expected): assert_array_equal(poly_tree.query_bulk(geometry, predicate="intersects"), expected) @pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_empty_tree():
64
64
60
37
27
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_empty_tree
test_nearest_empty_tree
1,187
1,190
1,187
1,188
e046af1ade55fafdc1594ca44095fed6b70bd55c
bigcode/the-stack
train
5e06c4e90aa872eee7acdf2e
train
function
@pytest.mark.parametrize( "geometry,expected", [ # endpoint is covered by first line (pygeos.points(0, 0), [0]), # point covered by first line (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []),...
@pytest.mark.parametrize( "geometry,expected", [ # endpoint is covered by first line (pygeos.points(0, 0), [0]), # point covered by first line (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []),...
assert_array_equal(line_tree.query(geometry, predicate="covered_by"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # endpoint is covered by first line (pygeos.points(0, 0), [0]), # point covered by first line (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []),...
410
128
427
410
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_covered_by_lines
test_query_covered_by_lines
776
804
776
803
5df41b26aa264c1b708add932d72720b3b5235b6
bigcode/the-stack
train
ed0d0e5d8d6ed2179f2a180c
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [(pygeos.points(0, 0), [0.0]), (pygeos.points(0.5, 0.5), [0.7071, 0.7071])], ) def test_nearest_all_return_distance(tree, geometry, expected): assert_array_equal( np.round(tree.ne...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [(pygeos.points(0, 0), [0.0]), (pygeos.points(0.5, 0.5), [0.7071, 0.7071])], ) def test_nearest_all_return_distance(tree, geometry, expected):
assert_array_equal( np.round(tree.nearest_all(geometry, return_distance=True)[1], 4), expected )
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [(pygeos.points(0, 0), [0.0]), (pygeos.points(0.5, 0.5), [0.7071, 0.7071])], ) def test_nearest_all_return_distance(tree, geometry, expected):
99
64
127
99
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_return_distance
test_nearest_all_return_distance
1,479
1,487
1,479
1,484
2f850147313afdc87d1732012f9d34026a573738
bigcode/the-stack
train
4f0595bfef2e56f4a7557bca
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_all_empty_tree(): tree = pygeos.STRtree([]) assert_array_equal(tree.nearest_all(point), [[], []])
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_all_empty_tree():
tree = pygeos.STRtree([]) assert_array_equal(tree.nearest_all(point), [[], []])
(poly_tree, geometry, expected): result = poly_tree.nearest(geometry) assert result[1] in expected @pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_all_empty_tree():
64
64
62
38
25
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_empty_tree
test_nearest_all_empty_tree
1,328
1,331
1,328
1,329
9094a3a1af49cc8bad46d95f5a92c5ebd86a4411
bigcode/the-stack
train
9e99d26fc9a261b40e443998
train
function
@pytest.mark.parametrize("geometry", [[], "foo", 1]) def test_query_bulk_wrong_type(tree, geometry): with pytest.raises(TypeError, match="Array should be of object dtype"): tree.query_bulk(geometry)
@pytest.mark.parametrize("geometry", [[], "foo", 1]) def test_query_bulk_wrong_type(tree, geometry):
with pytest.raises(TypeError, match="Array should be of object dtype"): tree.query_bulk(geometry)
_wrong_dimensions(tree): with pytest.raises(TypeError, match="Array should be one dimensional"): tree.query_bulk([[pygeos.points(0.5, 0.5)]]) @pytest.mark.parametrize("geometry", [[], "foo", 1]) def test_query_bulk_wrong_type(tree, geometry):
63
64
47
24
39
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_wrong_type
test_query_bulk_wrong_type
962
965
962
963
11430d52268e3cb81c24c39734ac4e33748ce979
bigcode/the-stack
train
ffaa1d668eff0ea3f9b59819
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.5, 0.5), [[0], [0]]), # at junction between 2 lines, will return both (pygeos.points(2, 2), [[0, 0], [1, 2]]), # contains one line, intersec...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.5, 0.5), [[0], [0]]), # at junction between 2 lines, will return both (pygeos.points(2, 2), [[0, 0], [1, 2]]), # contains one line, intersec...
assert_array_equal(line_tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.5, 0.5), [[0], [0]]), # at junction between 2 lines, will return both (pygeos.points(2, 2), [[0, 0], [1, 2]]), # contains one line, intersec...
506
156
520
506
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_lines
test_nearest_all_lines
1,393
1,417
1,393
1,416
81f160e74d05b7357a5ab170692e39247ad495fe
bigcode/the-stack
train
5861e6bb608fd445cf8d7ff1
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon ([pygeos.points(0, 0.5)], [[0], [0]]), ([pygeos.points(0.5, 0)], [[0], [0]]), # midpoint between two polygons intersects both ([pygeos.points(0.5, 0.5)], [[0, 0], [0, 1]]), # point inter...
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon ([pygeos.points(0, 0.5)], [[0], [0]]), ([pygeos.points(0.5, 0)], [[0], [0]]), # midpoint between two polygons intersects both ([pygeos.points(0.5, 0.5)], [[0, 0], [0, 1]]), # point inter...
assert_array_equal(poly_tree.query_bulk(geometry, predicate="intersects"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon ([pygeos.points(0, 0.5)], [[0], [0]]), ([pygeos.points(0.5, 0)], [[0], [0]]), # midpoint between two polygons intersects both ([pygeos.points(0.5, 0.5)], [[0, 0], [0, 1]]), # point inter...
505
156
523
505
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_intersects_polygons
test_query_bulk_intersects_polygons
1,151
1,184
1,151
1,183
7a4b9b67a6e00ff1b2645281f14b58575c3de09d
bigcode/the-stack
train
30ca4fb5b0bd51bf1455b7e9
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0, 0), [[0], [0]]), (pygeos.points(2, 2), [[0], [2]]), # 2 polygons in tree overlap point (pygeos.points(0.5, 0.5), [[0, 0], [0, 1]]), ...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0, 0), [[0], [0]]), (pygeos.points(2, 2), [[0], [2]]), # 2 polygons in tree overlap point (pygeos.points(0.5, 0.5), [[0, 0], [0, 1]]), ...
assert_array_equal(poly_tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0, 0), [[0], [0]]), (pygeos.points(2, 2), [[0], [2]]), # 2 polygons in tree overlap point (pygeos.points(0.5, 0.5), [[0, 0], [0, 1]]), ...
473
146
487
473
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_polygons
test_nearest_all_polygons
1,420
1,442
1,420
1,441
3a60a095aa210d5dc99e6c69d72953b6bcf2a19a
bigcode/the-stack
train
0e5fa05502b245447f2e1af7
train
function
def test_flush_geometries(): arr = pygeos.points(np.arange(10), np.arange(10)) tree = pygeos.STRtree(arr) # Dereference geometries arr[:] = None import gc gc.collect() # Still it does not lead to a segfault tree.query(point)
def test_flush_geometries():
arr = pygeos.points(np.arange(10), np.arange(10)) tree = pygeos.STRtree(arr) # Dereference geometries arr[:] = None import gc gc.collect() # Still it does not lead to a segfault tree.query(point)
_increases_refcount(point): _ = pygeos.STRtree(arr) def test_del_decreases_refcount(): arr = np.array([point]) tree = pygeos.STRtree(arr) with assert_decreases_refcount(point): del tree def test_flush_geometries():
64
64
73
7
56
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_flush_geometries
test_flush_geometries
90
99
90
90
d164d546bbf454053b90ee0167350c8625183e96
bigcode/the-stack
train
bdbb04fda5ee470e6bd5bd54
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any lines (not valid relation) (pygeos.points(0, 0), []), # box contains first line (touches edge of 1 but does not contain it) (box(0, 0, 1, 1), [0]), # buffer intersects 2 lines but contains neith...
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any lines (not valid relation) (pygeos.points(0, 0), []), # box contains first line (touches edge of 1 but does not contain it) (box(0, 0, 1, 1), [0]), # buffer intersects 2 lines but contains neith...
assert_array_equal(line_tree.query(geometry, predicate="contains"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any lines (not valid relation) (pygeos.points(0, 0), []), # box contains first line (touches edge of 1 but does not contain it) (box(0, 0, 1, 1), [0]), # buffer intersects 2 lines but contains neith...
231
74
247
231
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_contains_lines
test_query_contains_lines
435
453
435
452
9cc40925678cea38f6f51b5adbc1b257bcc21c74
bigcode/the-stack
train
4455acf106e3ee8933b12a5c
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect but not valid relation (pygeos.points(1, 1), []), # box contains points but touches only those at edges (box(3, 3, 6, 6), [3, 6]), ...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect but not valid relation (pygeos.points(1, 1), []), # box contains points but touches only those at edges (box(3, 3, 6, 6), [3, 6]), ...
assert_array_equal(tree.query(geometry, predicate="touches"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect but not valid relation (pygeos.points(1, 1), []), # box contains points but touches only those at edges (box(3, 3, 6, 6), [3, 6]), ...
205
66
221
205
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_touches_points
test_query_touches_points
610
628
610
627
ce2c6acdf8f57a5250217acc25d907e41a9be253
bigcode/the-stack
train
76a22de4011d57c480693003
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # at junction between 2 lines (pygeos.points(2, 2), [1, 2]), # contains one ...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # at junction between 2 lines (pygeos.points(2, 2), [1, 2]), # contains one ...
result = line_tree.nearest(geometry) assert result[1] in expected
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # at junction between 2 lines (pygeos.points(2, 2), [1, 2]), # contains one ...
400
125
419
400
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_lines_equidistant
test_nearest_lines_equidistant
1,262
1,287
1,262
1,285
aef41f5862a8210a75898450a1607d6cfb38903b
bigcode/the-stack
train
f1a809987b3ae0ef6c721f53
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects edge of envelopes of 2 polygons (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (pygeos.points(1, 1), [1]), # box overlaps envelope of 2 polygons (box(0, 0, 1, 1), [0, 1]), ...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects edge of envelopes of 2 polygons (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (pygeos.points(1, 1), [1]), # box overlaps envelope of 2 polygons (box(0, 0, 1, 1), [0, 1]), ...
assert_array_equal(poly_tree.query(geometry), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects edge of envelopes of 2 polygons (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (pygeos.points(1, 1), [1]), # box overlaps envelope of 2 polygons (box(0, 0, 1, 1), [0, 1]), ...
287
89
299
287
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_polygons
test_query_polygons
180
200
180
199
7647ed35fcbd081e6a67b92504a2594188c25fc3
bigcode/the-stack
train
bcb45ee406b155cb772338f3
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), # midpoint between two polygons intersects both (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (...
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), # midpoint between two polygons intersects both (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (...
assert_array_equal(poly_tree.query(geometry, predicate="intersects"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), # midpoint between two polygons intersects both (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (...
354
111
371
354
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_intersects_polygons
test_query_intersects_polygons
296
321
296
320
0927fc15bd68011910a12605511fecbd5823872d
bigcode/the-stack
train
c4c14af6d4c853ded02e90dc
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (box(3, 3, 6, 6), [3, 4, 5, 6]), # envelope of buffer contains more points than i...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (box(3, 3, 6, 6), [3, 4, 5, 6]), # envelope of buffer contains more points than i...
assert_array_equal(tree.query(geometry, predicate="intersects"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (box(3, 3, 6, 6), [3, 4, 5, 6]), # envelope of buffer contains more points than i...
382
119
398
382
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_intersects_points
test_query_intersects_points
235
267
235
266
2cfc7b31c54dd231ac868108e98cc1b0e6140b62
bigcode/the-stack
train
e854065415b51816326ccf0d
train
function
@pytest.mark.parametrize( "geometry,count, hits", [ # Empty array produces empty tree ([], 0, 0), ([point], 1, 1), # None geometries are ignored when creating tree ([None], 0, 0), ([point, None], 1, 1), # empty geometries are ignored when creating tree ...
@pytest.mark.parametrize( "geometry,count, hits", [ # Empty array produces empty tree ([], 0, 0), ([point], 1, 1), # None geometries are ignored when creating tree ([None], 0, 0), ([point, None], 1, 1), # empty geometries are ignored when creating tree ...
tree = pygeos.STRtree(np.array(geometry)) assert len(tree) == count assert tree.query(box(0, 0, 100, 100)).size == hits
@pytest.mark.parametrize( "geometry,count, hits", [ # Empty array produces empty tree ([], 0, 0), ([point], 1, 1), # None geometries are ignored when creating tree ([None], 0, 0), ([point, None], 1, 1), # empty geometries are ignored when creating tree ...
144
64
187
144
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_init
test_init
51
69
51
66
1bbe18a02f08e330a0ccd20228ebfbcdbe8c788e
bigcode/the-stack
train
803a8a3d4a922b3d549ea52e
train
function
@pytest.mark.parametrize( "tree_geometry,geometry,expected", [ # Empty tree returns no results ([], [None], (2, 0)), ([], [point], (2, 0)), # None is ignored when constructing and querying the tree ([None], [None], (2, 0)), ([point], [None], (2, 0)), ([Non...
@pytest.mark.parametrize( "tree_geometry,geometry,expected", [ # Empty tree returns no results ([], [None], (2, 0)), ([], [point], (2, 0)), # None is ignored when constructing and querying the tree ([None], [None], (2, 0)), ([point], [None], (2, 0)), ([Non...
tree = pygeos.STRtree(np.array(tree_geometry)) assert tree.query_bulk(np.array(geometry)).shape == expected
@pytest.mark.parametrize( "tree_geometry,geometry,expected", [ # Empty tree returns no results ([], [None], (2, 0)), ([], [point], (2, 0)), # None is ignored when constructing and querying the tree ([None], [None], (2, 0)), ([point], [None], (2, 0)), ([Non...
233
78
261
233
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk
test_query_bulk
929
954
929
952
632914a30225158fb36eb32dbce29e3c2d2dd6b4
bigcode/the-stack
train
a5e707fa40dd8f29e5e4f8ad
train
function
def test_query_unsupported_predicate(tree): # valid GEOS binary predicate, but not supported for query with pytest.raises(ValueError): tree.query(pygeos.points(1, 1), predicate="disjoint")
def test_query_unsupported_predicate(tree): # valid GEOS binary predicate, but not supported for query
with pytest.raises(ValueError): tree.query(pygeos.points(1, 1), predicate="disjoint")
_tree.query(geometry), expected) def test_query_invalid_predicate(tree): with pytest.raises(ValueError): tree.query(pygeos.points(1, 1), predicate="bad_predicate") def test_query_unsupported_predicate(tree): # valid GEOS binary predicate, but not supported for query
64
64
48
23
41
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_unsupported_predicate
test_query_unsupported_predicate
208
211
208
209
2c8d5d07638b50cf795a750833c44c37ef2b9668
bigcode/the-stack
train
aa892bdc431c37272497b334
train
function
def test_query_invalid_geometry(tree): with pytest.raises(TypeError): tree.query("I am not a geometry")
def test_query_invalid_geometry(tree):
with pytest.raises(TypeError): tree.query("I am not a geometry")
gc.collect() # Still it does not lead to a segfault tree.query(point) def test_geometries_property(): arr = np.array([point]) tree = pygeos.STRtree(arr) assert arr is tree.geometries def test_query_invalid_geometry(tree):
64
64
24
7
56
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_invalid_geometry
test_query_invalid_geometry
108
110
108
108
30bcda1afd6f722a7bc5381f5267250ebb2e2264
bigcode/the-stack
train
51b0a4be241f930f10d23eb8
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line ([pygeos.points(0, 0)], [[0], [0]]), ([pygeos.points(0.5, 0.5)], [[0], [0]]), # point within envelope of first line ([pygeos.points(0, 0.5)], [[0], [0]]), # point at shared vertex betwe...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line ([pygeos.points(0, 0)], [[0], [0]]), ([pygeos.points(0.5, 0.5)], [[0], [0]]), # point within envelope of first line ([pygeos.points(0, 0.5)], [[0], [0]]), # point at shared vertex betwe...
assert_array_equal(line_tree.query_bulk(geometry), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line ([pygeos.points(0, 0)], [[0], [0]]), ([pygeos.points(0.5, 0.5)], [[0], [0]]), # point within envelope of first line ([pygeos.points(0, 0.5)], [[0], [0]]), # point at shared vertex betwe...
298
93
311
298
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_lines
test_query_bulk_lines
1,001
1,020
1,001
1,019
e4cfd7f853f71c2962f4f8bf02328033c70534c5
bigcode/the-stack
train
52091834e2fbb94675e901b0
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon but not valid relation (pygeos.points(0, 0.5), []), # box overlaps 2 polygons but not valid relation (box(0, 0, 1.5, 1.5), []), # buffer overlaps 3 polygons but not valid relation (pygeo...
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon but not valid relation (pygeos.points(0, 0.5), []), # box overlaps 2 polygons but not valid relation (box(0, 0, 1.5, 1.5), []), # buffer overlaps 3 polygons but not valid relation (pygeo...
assert_array_equal(poly_tree.query(geometry, predicate="crosses"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon but not valid relation (pygeos.points(0, 0.5), []), # box overlaps 2 polygons but not valid relation (box(0, 0, 1.5, 1.5), []), # buffer overlaps 3 polygons but not valid relation (pygeo...
164
64
181
164
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_crosses_polygons
test_query_crosses_polygons
591
605
591
604
943c8143d03d947caad3dd0b80e8b408fc38c43b
bigcode/the-stack
train
152795ee847456ede40beb5f
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects edge of envelopes of 2 polygons ([pygeos.points(0.5, 0.5)], [[0, 0], [0, 1]]), # point intersects single polygon ([pygeos.points(1, 1)], [[0], [1]]), # box overlaps envelope of 2 polygons ([box(0,...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects edge of envelopes of 2 polygons ([pygeos.points(0.5, 0.5)], [[0, 0], [0, 1]]), # point intersects single polygon ([pygeos.points(1, 1)], [[0], [1]]), # box overlaps envelope of 2 polygons ([box(0,...
assert_array_equal(poly_tree.query_bulk(geometry), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects edge of envelopes of 2 polygons ([pygeos.points(0.5, 0.5)], [[0, 0], [0, 1]]), # point intersects single polygon ([pygeos.points(1, 1)], [[0], [1]]), # box overlaps envelope of 2 polygons ([box(0,...
440
135
453
440
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_polygons
test_query_bulk_polygons
1,023
1,051
1,023
1,050
e2171f6e5517fb67bdd3f2f83fe01c13f2928827
bigcode/the-stack
train
32d992bb90d64e9895d947a9
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects line but is completely contained by it (pygeos.points(0, 0), []), # box overlaps second line (contains first line) # but of different dimensions so does not overlap (box(0, 0, 1.5, 1.5), []), # bu...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects line but is completely contained by it (pygeos.points(0, 0), []), # box overlaps second line (contains first line) # but of different dimensions so does not overlap (box(0, 0, 1.5, 1.5), []), # bu...
assert_array_equal(line_tree.query(geometry, predicate="overlaps"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects line but is completely contained by it (pygeos.points(0, 0), []), # box overlaps second line (contains first line) # but of different dimensions so does not overlap (box(0, 0, 1.5, 1.5), []), # bu...
235
75
252
235
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_overlaps_lines
test_query_overlaps_lines
507
526
507
525
9df29c353f73871219fc28830cf3f3d98e860dd3
bigcode/the-stack
train
79224565eb8f24c7bc5b7216
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), []), # point is at edge of first polygon (pygeos.points(HALF_UNIT_DIAG + EPS, 0), [0]), # box overlaps envelope of 2 polygons does not touch any at edge (box(0, 0...
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), []), # point is at edge of first polygon (pygeos.points(HALF_UNIT_DIAG + EPS, 0), [0]), # box overlaps envelope of 2 polygons does not touch any at edge (box(0, 0...
assert_array_equal(poly_tree.query(geometry, predicate="touches"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), []), # point is at edge of first polygon (pygeos.points(HALF_UNIT_DIAG + EPS, 0), [0]), # box overlaps envelope of 2 polygons does not touch any at edge (box(0, 0...
237
76
254
237
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_touches_polygons
test_query_touches_polygons
657
675
657
674
2f55900fe188fba848b4d2fbc86e9cd2c70e81b3
bigcode/the-stack
train
8a070d4d438867dd0cc94bb6
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.5, 0.5), [[0], [0]]), (pygeos.points(1.5, 0.5), [[0], [0]]), (pygeos.box(0.5, 1.5, 1, 2), [[0], [1]]), (pygeos.linestrings([[0, 0.5], [1, 2....
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.5, 0.5), [[0], [0]]), (pygeos.points(1.5, 0.5), [[0], [0]]), (pygeos.box(0.5, 1.5, 1, 2), [[0], [1]]), (pygeos.linestrings([[0, 0.5], [1, 2....
assert_array_equal(line_tree.nearest(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.5, 0.5), [[0], [0]]), (pygeos.points(1.5, 0.5), [[0], [0]]), (pygeos.box(0.5, 1.5, 1, 2), [[0], [1]]), (pygeos.linestrings([[0, 0.5], [1, 2....
164
64
177
164
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_lines
test_nearest_lines
1,248
1,259
1,248
1,258
a27537b46d7c92a42cfcd796c73be032908d1e95
bigcode/the-stack
train
67aca3096efd80e9feb3cadd
train
function
def test_query_invalid_predicate(tree): with pytest.raises(ValueError): tree.query(pygeos.points(1, 1), predicate="bad_predicate")
def test_query_invalid_predicate(tree):
with pytest.raises(ValueError): tree.query(pygeos.points(1, 1), predicate="bad_predicate")
(pygeos.multipoints([[5, 7], [7, 5]]), [5, 6, 7]), ], ) def test_query_polygons(poly_tree, geometry, expected): assert_array_equal(poly_tree.query(geometry), expected) def test_query_invalid_predicate(tree):
64
64
34
8
56
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_invalid_predicate
test_query_invalid_predicate
203
205
203
203
abc4872918d10c4bea8fdc649f043a2004c43790
bigcode/the-stack
train
18fb619fe5c5b6759111aa88
train
function
@pytest.fixture def line_tree(): x = np.arange(10) y = np.arange(10) offset = 1 geoms = pygeos.linestrings(np.array([[x, x + offset], [y, y + offset]]).T) yield pygeos.STRtree(geoms)
@pytest.fixture def line_tree():
x = np.arange(10) y = np.arange(10) offset = 1 geoms = pygeos.linestrings(np.array([[x, x + offset], [y, y + offset]]).T) yield pygeos.STRtree(geoms)
_UNIT_DIAG = math.sqrt(2) / 2 EPS = 1e-9 @pytest.fixture def tree(): geoms = pygeos.points(np.arange(10), np.arange(10)) yield pygeos.STRtree(geoms) @pytest.fixture def line_tree():
64
64
70
7
57
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
line_tree
line_tree
32
38
32
33
a8b3e1a98099d7572a68d63564509a6cf829dc77
bigcode/the-stack
train
20883ba5c3e5318025b2619c
train
function
@pytest.fixture def poly_tree(): # create buffers so that midpoint between two buffers intersects # each buffer. NOTE: add EPS to help mitigate rounding errors at midpoint. geoms = pygeos.buffer( pygeos.points(np.arange(10), np.arange(10)), HALF_UNIT_DIAG + EPS, quadsegs=32 ) yield pygeos.S...
@pytest.fixture def poly_tree(): # create buffers so that midpoint between two buffers intersects # each buffer. NOTE: add EPS to help mitigate rounding errors at midpoint.
geoms = pygeos.buffer( pygeos.points(np.arange(10), np.arange(10)), HALF_UNIT_DIAG + EPS, quadsegs=32 ) yield pygeos.STRtree(geoms)
, x + offset], [y, y + offset]]).T) yield pygeos.STRtree(geoms) @pytest.fixture def poly_tree(): # create buffers so that midpoint between two buffers intersects # each buffer. NOTE: add EPS to help mitigate rounding errors at midpoint.
64
64
88
37
27
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
poly_tree
poly_tree
41
48
41
44
6a80d14adaedb694d45a9d2cc60ea731f7abef2f
bigcode/the-stack
train
8cb92828a2abaad00dd6ecd5
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (2 are at edges and not contained) (box(3, 3, 6, 6), [4, 5]), # envelope of buffe...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (2 are at edges and not contained) (box(3, 3, 6, 6), [4, 5]), # envelope of buffe...
assert_array_equal(tree.query(geometry, predicate="contains"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (2 are at edges and not contained) (box(3, 3, 6, 6), [4, 5]), # envelope of buffe...
307
96
322
307
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_contains_points
test_query_contains_points
408
432
408
431
d33dc94f95b2c4655f10a0e78c7c7a166b0076c1
bigcode/the-stack
train
35c7c1ddaf06a3c39ccda8c5
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point does not cover any lines (not valid relation) (pygeos.points(0, 0), []), # box covers first line (intersects another does not contain it) (box(0, 0, 1.5, 1.5), [0]), # box completely covers 2 lines (touches edges of...
@pytest.mark.parametrize( "geometry,expected", [ # point does not cover any lines (not valid relation) (pygeos.points(0, 0), []), # box covers first line (intersects another does not contain it) (box(0, 0, 1.5, 1.5), [0]), # box completely covers 2 lines (touches edges of...
assert_array_equal(line_tree.query(geometry, predicate="covers"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point does not cover any lines (not valid relation) (pygeos.points(0, 0), []), # box covers first line (intersects another does not contain it) (box(0, 0, 1.5, 1.5), [0]), # box completely covers 2 lines (touches edges of...
282
89
298
282
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_covers_lines
test_query_covers_lines
706
726
706
725
db59f213732c9b27af292b768c2d2da7ed900343
bigcode/the-stack
train
1abaa59885943f6ff67df34c
train
function
def test_init_increases_refcount(): arr = np.array([point]) with assert_increases_refcount(point): _ = pygeos.STRtree(arr)
def test_init_increases_refcount():
arr = np.array([point]) with assert_increases_refcount(point): _ = pygeos.STRtree(arr)
== count assert tree.query(box(0, 0, 100, 100)).size == hits def test_init_with_invalid_geometry(): with pytest.raises(TypeError): pygeos.STRtree(np.array(["Not a geometry"], dtype=object)) def test_init_increases_refcount():
64
64
36
8
56
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_init_increases_refcount
test_init_increases_refcount
77
80
77
77
117aef8b3889493d241f47077b8a5918990cb368
bigcode/the-stack
train
3739d068fcf1946f359129b7
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line but is completely in common with line (pygeos.points(0, 0), []), # box overlaps envelope of first 2 lines, contains first and crosses second (box(0, 0, 1.5, 1.5), [1]), # buffer intersects 2 li...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line but is completely in common with line (pygeos.points(0, 0), []), # box overlaps envelope of first 2 lines, contains first and crosses second (box(0, 0, 1.5, 1.5), [1]), # buffer intersects 2 li...
assert_array_equal(line_tree.query(geometry, predicate="crosses"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line but is completely in common with line (pygeos.points(0, 0), []), # box overlaps envelope of first 2 lines, contains first and crosses second (box(0, 0, 1.5, 1.5), [1]), # buffer intersects 2 li...
231
74
248
231
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_crosses_lines
test_query_crosses_lines
570
588
570
587
7c353dcbf0d3d83c26c5476a1ba9ce5720f75150
bigcode/the-stack
train
bb500efbd0461b72bb78f168
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # 2 equidistant points in tree (pygeos.points(0.5, 0.5), [0, 1]), # multiple...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # 2 equidistant points in tree (pygeos.points(0.5, 0.5), [0, 1]), # multiple...
result = tree.nearest(geometry) assert result[1] in expected
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # 2 equidistant points in tree (pygeos.points(0.5, 0.5), [0, 1]), # multiple...
185
64
203
185
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_points_equidistant
test_nearest_points_equidistant
1,230
1,245
1,230
1,243
ac37e1d662efaf3dd703f95185ac1922e91348c9
bigcode/the-stack
train
dbb92b97186a21601ceb73bd
train
function
@pytest.fixture def tree(): geoms = pygeos.points(np.arange(10), np.arange(10)) yield pygeos.STRtree(geoms)
@pytest.fixture def tree():
geoms = pygeos.points(np.arange(10), np.arange(10)) yield pygeos.STRtree(geoms)
creases_refcount, empty, empty_line_string, empty_point, point, ) # the distance between 2 points spaced at whole numbers along a diagonal HALF_UNIT_DIAG = math.sqrt(2) / 2 EPS = 1e-9 @pytest.fixture def tree():
64
64
36
6
57
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
tree
tree
26
29
26
27
f51aadeea00cfddeaf247b340117dde7aefa3f4c
bigcode/the-stack
train
1b7175a5a091698aab3160a0
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry,expected", [(None, [[], []]), ([None], [[], []])]) def test_nearest_none(tree, geometry, expected): assert_array_equal(tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry,expected", [(None, [[], []]), ([None], [[], []])]) def test_nearest_none(tree, geometry, expected):
assert_array_equal(tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry,expected", [(None, [[], []]), ([None], [[], []])]) def test_nearest_none(tree, geometry, expected):
64
64
77
64
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_none
test_nearest_none
1,201
1,204
1,201
1,203
4bc5e608b793713f615cc061d9ec8f3102a25137
bigcode/the-stack
train
31b6b42e9bb96f62721f60f2
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,max_distance,expected", [ # using unset max_distance should return all nearest (pygeos.points(0.5, 0.5), None, [[0, 0], [0, 1]]), # using large max_distance should return all nea...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,max_distance,expected", [ # using unset max_distance should return all nearest (pygeos.points(0.5, 0.5), None, [[0, 0], [0, 1]]), # using large max_distance should return all nea...
assert_array_equal(tree.nearest_all(geometry, max_distance=max_distance), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,max_distance,expected", [ # using unset max_distance should return all nearest (pygeos.points(0.5, 0.5), None, [[0, 0], [0, 1]]), # using large max_distance should return all nea...
236
76
254
236
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_max_distance
test_nearest_all_max_distance
1,445
1,460
1,445
1,459
96fa9a312137a7454657fa64cfb299e3116e34e6
bigcode/the-stack
train
a6c0d1f68e5cad723ce574b1
train
function
def test_query_with_prepared(tree): geom = box(0, 0, 1, 1) expected = tree.query(geom, predicate="intersects") pygeos.prepare(geom) assert_array_equal(expected, tree.query(geom, predicate="intersects"))
def test_query_with_prepared(tree):
geom = box(0, 0, 1, 1) expected = tree.query(geom, predicate="intersects") pygeos.prepare(geom) assert_array_equal(expected, tree.query(geom, predicate="intersects"))
os.Geometry("POINT (0 0)"), None, pygeos.Geometry("POINT (2 2)")] ) assert tree.query(pygeos.points(2, 2), predicate="intersects") == [2] ### predicate == 'intersects' def test_query_with_prepared(tree):
64
64
61
8
56
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_with_prepared
test_query_with_prepared
225
230
225
225
381fbb9bbdd8fd110db3f1ed1643fd492b5c22c5
bigcode/the-stack
train
36443eb1be429d81f04b5826
train
function
def test_query_bulk_wrong_dimensions(tree): with pytest.raises(TypeError, match="Array should be one dimensional"): tree.query_bulk([[pygeos.points(0.5, 0.5)]])
def test_query_bulk_wrong_dimensions(tree):
with pytest.raises(TypeError, match="Array should be one dimensional"): tree.query_bulk([[pygeos.points(0.5, 0.5)]])
, empty_line_string], (2, 1), ), ], ) def test_query_bulk(tree_geometry, geometry, expected): tree = pygeos.STRtree(np.array(tree_geometry)) assert tree.query_bulk(np.array(geometry)).shape == expected def test_query_bulk_wrong_dimensions(tree):
64
64
43
8
55
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_wrong_dimensions
test_query_bulk_wrong_dimensions
957
959
957
957
1b75b5608f01f4aab6d843a7cb1baa34b436cd27
bigcode/the-stack
train
985008b1fd83994d19400db0
train
function
def test_query_bulk_invalid_predicate(tree): with pytest.raises(ValueError): tree.query_bulk(pygeos.points(1, 1), predicate="bad_predicate")
def test_query_bulk_invalid_predicate(tree):
with pytest.raises(ValueError): tree.query_bulk(pygeos.points(1, 1), predicate="bad_predicate")
[7, 5]])], [[0, 0, 0], [5, 6, 7]]), ], ) def test_query_bulk_polygons(poly_tree, geometry, expected): assert_array_equal(poly_tree.query_bulk(geometry), expected) def test_query_bulk_invalid_predicate(tree):
64
64
36
9
55
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_invalid_predicate
test_query_bulk_invalid_predicate
1,054
1,056
1,054
1,054
7afb195da13f22fa25522f8e51c08280ce88b20f
bigcode/the-stack
train
cefc35a239fbd49391a98ba3
train
function
@pytest.mark.parametrize( "geometry,expected", [ # None of the following conditions satisfy the relation for linestrings # because they have no interior: # "a contains b if no points of b lie in the exterior of a, and at least one # point of the interior of b lies in the interior...
@pytest.mark.parametrize( "geometry,expected", [ # None of the following conditions satisfy the relation for linestrings # because they have no interior: # "a contains b if no points of b lie in the exterior of a, and at least one # point of the interior of b lies in the interior...
assert_array_equal( line_tree.query(geometry, predicate="contains_properly"), expected )
@pytest.mark.parametrize( "geometry,expected", [ # None of the following conditions satisfy the relation for linestrings # because they have no interior: # "a contains b if no points of b lie in the exterior of a, and at least one # point of the interior of b lies in the interior...
300
96
323
300
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_contains_properly_lines
test_query_contains_properly_lines
877
899
877
896
1d01e5f711cb3ab743866e934edacc92ceedf4a7
bigcode/the-stack
train
0dc187c5099f69c829b901a5
train
function
def test_query_none(tree): assert tree.query(None).size == 0
def test_query_none(tree):
assert tree.query(None).size == 0
test_geometries_property(): arr = np.array([point]) tree = pygeos.STRtree(arr) assert arr is tree.geometries def test_query_invalid_geometry(tree): with pytest.raises(TypeError): tree.query("I am not a geometry") def test_query_none(tree):
64
64
17
6
58
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_none
test_query_none
113
114
113
113
a6cabc64214f5915df94185f3c74fccb11f33e96
bigcode/the-stack
train
c5594ee9421beda0a0fa72eb
train
function
def test_del_decreases_refcount(): arr = np.array([point]) tree = pygeos.STRtree(arr) with assert_decreases_refcount(point): del tree
def test_del_decreases_refcount():
arr = np.array([point]) tree = pygeos.STRtree(arr) with assert_decreases_refcount(point): del tree
Error): pygeos.STRtree(np.array(["Not a geometry"], dtype=object)) def test_init_increases_refcount(): arr = np.array([point]) with assert_increases_refcount(point): _ = pygeos.STRtree(arr) def test_del_decreases_refcount():
64
64
40
8
56
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_del_decreases_refcount
test_del_decreases_refcount
83
87
83
83
abf19f93d620db00c7c1a7767e4a11adbcb99eb0
bigcode/the-stack
train
8530f189a713139fb4a7af40
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box not within points (box(3, 3, 6, 6), []), # envelope of buffer not within points (pygeos.b...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box not within points (box(3, 3, 6, 6), []), # envelope of buffer not within points (pygeos.b...
assert_array_equal(tree.query(geometry, predicate="within"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box not within points (box(3, 3, 6, 6), []), # envelope of buffer not within points (pygeos.b...
246
78
261
246
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_within_points
test_query_within_points
325
346
325
345
09ec384ad205c0c0a103db71e23da0624e488355
bigcode/the-stack
train
b4209a57d30701927cd926b5
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (box(0, 0, 1, 1), [0, 1]), # box contains points (box(5, 5, 15, 15), [5, ...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (box(0, 0, 1, 1), [0, 1]), # box contains points (box(5, 5, 15, 15), [5, ...
assert_array_equal(tree.query(geometry), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box contains points (box(0, 0, 1, 1), [0, 1]), # box contains points (box(5, 5, 15, 15), [5, ...
207
65
218
207
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_points
test_query_points
137
155
137
154
2d5b14de2c395de48ed4ad1c5df960afeacf6d8b
bigcode/the-stack
train
0069e93212757f113964837d
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry", ["I am not a geometry"]) def test_nearest_invalid_geom(tree, geometry): with pytest.raises(TypeError): tree.nearest(geometry)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry", ["I am not a geometry"]) def test_nearest_invalid_geom(tree, geometry):
with pytest.raises(TypeError): tree.nearest(geometry)
_array_equal(tree.nearest(point), [[], []]) @pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry", ["I am not a geometry"]) def test_nearest_invalid_geom(tree, geometry):
64
64
67
53
11
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_invalid_geom
test_nearest_invalid_geom
1,193
1,197
1,193
1,195
4a0049a2f864fe583d08210ccc0649d666ca3dff
bigcode/the-stack
train
e20d637a7319eb4f9b3b1ab6
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [(empty, [[], []]), ([empty, point], [[1, 1], [2, 3]])] ) def test_nearest_all_empty_geom(tree, geometry, expected): assert_array_equal(tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [(empty, [[], []]), ([empty, point], [[1, 1], [2, 3]])] ) def test_nearest_all_empty_geom(tree, geometry, expected):
assert_array_equal(tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [(empty, [[], []]), ([empty, point], [[1, 1], [2, 3]])] ) def test_nearest_all_empty_geom(tree, geometry, expected):
79
64
92
79
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_empty_geom
test_nearest_all_empty_geom
1,356
1,361
1,356
1,360
b62ca3f96a4fdff39284fdcb31c9ffa914f47a9a
bigcode/the-stack
train
260e4e9392deb31115929254
train
function
@pytest.mark.parametrize( "geometry,expected", [ # endpoint not within first line (pygeos.points(0, 0), []), # point within first line (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []), ...
@pytest.mark.parametrize( "geometry,expected", [ # endpoint not within first line (pygeos.points(0, 0), []), # point within first line (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []), ...
assert_array_equal(line_tree.query(geometry, predicate="within"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # endpoint not within first line (pygeos.points(0, 0), []), # point within first line (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []), ...
295
93
311
295
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_within_lines
test_query_within_lines
349
372
349
371
0f02127ad8fb317735ac5aa483d0d370cd8ff56e
bigcode/the-stack
train
bef01f4b03d36bdfd7102f04
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), # midpoint between two polygons intersects both (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (...
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), # midpoint between two polygons intersects both (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (...
assert_array_equal(poly_tree.query(geometry, predicate="within"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point within first polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), # midpoint between two polygons intersects both (pygeos.points(0.5, 0.5), [0, 1]), # point intersects single polygon (...
407
126
423
407
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_within_polygons
test_query_within_polygons
375
404
375
403
5f30937a60343be444cfe43cf0f160dac6e6affd
bigcode/the-stack
train
b9116cd21087ef0178dc69aa
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,max_distance", [(pygeos.points(0.5, 0.5), 0), (pygeos.points(0.5, 0.5), -1)], ) def test_nearest_all_invalid_max_distance(tree, geometry, max_distance): with pytest.raises(ValueError, match="max_dis...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,max_distance", [(pygeos.points(0.5, 0.5), 0), (pygeos.points(0.5, 0.5), -1)], ) def test_nearest_all_invalid_max_distance(tree, geometry, max_distance):
with pytest.raises(ValueError, match="max_distance must be greater than 0"): tree.nearest_all(geometry, max_distance=max_distance)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,max_distance", [(pygeos.points(0.5, 0.5), 0), (pygeos.points(0.5, 0.5), -1)], ) def test_nearest_all_invalid_max_distance(tree, geometry, max_distance):
93
64
124
93
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_invalid_max_distance
test_nearest_all_invalid_max_distance
1,463
1,470
1,463
1,468
a51b8f3276a3eb34c9f3d58de6b8ef96ce1b7d91
bigcode/the-stack
train
536fbcbc5b2666ee693c7faa
train
function
def test_query_bulk_with_prepared(tree): geom = np.array([box(0, 0, 1, 1), box(3, 3, 5, 5)]) expected = tree.query_bulk(geom, predicate="intersects") # test with array of partially prepared geometries pygeos.prepare(geom[0]) assert_array_equal(expected, tree.query_bulk(geom, predicate="intersects")...
def test_query_bulk_with_prepared(tree):
geom = np.array([box(0, 0, 1, 1), box(3, 3, 5, 5)]) expected = tree.query_bulk(geom, predicate="intersects") # test with array of partially prepared geometries pygeos.prepare(geom[0]) assert_array_equal(expected, tree.query_bulk(geom, predicate="intersects")) # test with fully prepared geometr...
assert_array_equal(poly_tree.query_bulk(geometry), expected) def test_query_bulk_invalid_predicate(tree): with pytest.raises(ValueError): tree.query_bulk(pygeos.points(1, 1), predicate="bad_predicate") ### predicate == 'intersects' def test_query_bulk_with_prepared(tree):
64
64
127
9
55
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_with_prepared
test_query_bulk_with_prepared
1,062
1,072
1,062
1,062
c1e9e56f96f01b4bfdb713f59e84ba358b15d38c
bigcode/the-stack
train
9af2b4b5b7e4d923165cd05a
train
function
@pytest.mark.parametrize( "tree_geometry, geometry,expected", [ ([point], box(0, 0, 10, 10), [0]), # None is ignored in the tree, but the index of the valid geometry should # be retained. ([None, point], box(0, 0, 10, 10), [1]), ([None, empty, point], box(0, 0, 10, 10), [...
@pytest.mark.parametrize( "tree_geometry, geometry,expected", [ ([point], box(0, 0, 10, 10), [0]), # None is ignored in the tree, but the index of the valid geometry should # be retained. ([None, point], box(0, 0, 10, 10), [1]), ([None, empty, point], box(0, 0, 10, 10), [...
tree = pygeos.STRtree(np.array(tree_geometry)) assert_array_equal(tree.query(geometry), expected)
@pytest.mark.parametrize( "tree_geometry, geometry,expected", [ ([point], box(0, 0, 10, 10), [0]), # None is ignored in the tree, but the index of the valid geometry should # be retained. ([None, point], box(0, 0, 10, 10), [1]), ([None, empty, point], box(0, 0, 10, 10), [...
117
64
142
117
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query
test_query
122
134
122
132
6ce74a8e1c2ed9f18393209a801d91d5274f3e34
bigcode/the-stack
train
facb808a7aba0b9f24360b40
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect but do not overlap (pygeos.points(1, 1), []), # box overlaps points including those at edge but does not overlap # (completely contains all...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect but do not overlap (pygeos.points(1, 1), []), # box overlaps points including those at edge but does not overlap # (completely contains all...
assert_array_equal(tree.query(geometry, predicate="overlaps"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect but do not overlap (pygeos.points(1, 1), []), # box overlaps points including those at edge but does not overlap # (completely contains all...
279
88
295
279
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_overlaps_points
test_query_overlaps_points
482
504
482
503
8e70a33f199da2e464ad32e9003daec7beb35c6c
bigcode/the-stack
train
56f8ed67e9e90dbd055b4ec4
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point does not cover any polygons (not valid relation) (pygeos.points(0, 0), []), # box overlaps envelope of 2 polygons but does not completely cover either (box(0, 0, 1, 1), []), # larger box intersects 3 polygons but co...
@pytest.mark.parametrize( "geometry,expected", [ # point does not cover any polygons (not valid relation) (pygeos.points(0, 0), []), # box overlaps envelope of 2 polygons but does not completely cover either (box(0, 0, 1, 1), []), # larger box intersects 3 polygons but co...
assert_array_equal(poly_tree.query(geometry, predicate="covers"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point does not cover any polygons (not valid relation) (pygeos.points(0, 0), []), # box overlaps envelope of 2 polygons but does not completely cover either (box(0, 0, 1, 1), []), # larger box intersects 3 polygons but co...
247
78
263
247
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_covers_polygons
test_query_covers_polygons
729
748
729
747
0101f59199c75e1cf4abd2f75beeb7b337b92360
bigcode/the-stack
train
ebb94c12177c019c4ed7481c
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect and thus no point is outside the other (pygeos.points(1, 1), [1]), # box covers any points that intersect or are within (box(3, 3, 6, 6), [...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect and thus no point is outside the other (pygeos.points(1, 1), [1]), # box covers any points that intersect or are within (box(3, 3, 6, 6), [...
assert_array_equal(tree.query(geometry, predicate="covers"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect and thus no point is outside the other (pygeos.points(1, 1), [1]), # box covers any points that intersect or are within (box(3, 3, 6, 6), [...
330
103
345
330
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_covers_points
test_query_covers_points
679
703
679
702
05d15fe2f6ed0ed0eedf436909382542e6011135
bigcode/the-stack
train
9499d6c00f98b0f66508a7fe
train
function
def test_init_with_invalid_geometry(): with pytest.raises(TypeError): pygeos.STRtree(np.array(["Not a geometry"], dtype=object))
def test_init_with_invalid_geometry():
with pytest.raises(TypeError): pygeos.STRtree(np.array(["Not a geometry"], dtype=object))
), ], ) def test_init(geometry, count, hits): tree = pygeos.STRtree(np.array(geometry)) assert len(tree) == count assert tree.query(box(0, 0, 100, 100)).size == hits def test_init_with_invalid_geometry():
64
64
32
7
56
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_init_with_invalid_geometry
test_init_with_invalid_geometry
72
74
72
72
791e7d84a9415aaffafa090b42404141cdf4118b
bigcode/the-stack
train
41d44f8c1918c12d97e50043
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect ([pygeos.points(0.5, 0.5)], [[], []]), # points intersect ([pygeos.points(1, 1)], [[0], [1]]), # first and last points intersect ( [pygeos.points(1, 1), pygeos.points(-1, -1), p...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect ([pygeos.points(0.5, 0.5)], [[], []]), # points intersect ([pygeos.points(1, 1)], [[0], [1]]), # first and last points intersect ( [pygeos.points(1, 1), pygeos.points(-1, -1), p...
assert_array_equal(tree.query_bulk(geometry), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect ([pygeos.points(0.5, 0.5)], [[], []]), # points intersect ([pygeos.points(1, 1)], [[0], [1]]), # first and last points intersect ( [pygeos.points(1, 1), pygeos.points(-1, -1), p...
446
137
458
446
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_points
test_query_bulk_points
968
998
968
997
62785dc0e75234d0f6b25057ca5defa9da12ad35
bigcode/the-stack
train
a72023d1138e7612bfb44727
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box not covered by points (box(3, 3, 6, 6), []), # envelope of buffer not covered by points (...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box not covered by points (box(3, 3, 6, 6), []), # envelope of buffer not covered by points (...
assert_array_equal(tree.query(geometry, predicate="covered_by"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # box not covered by points (box(3, 3, 6, 6), []), # envelope of buffer not covered by points (...
251
80
267
251
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_covered_by_points
test_query_covered_by_points
752
773
752
772
8cfadb95fd3b73e7c3b420169dd9604fdc79032e
bigcode/the-stack
train
95b6d96e60c96b9e35cb1f6d
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line (pygeos.points(0, 0.5), [0]), # point at shared vertex between 2 lines (pygeos....
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line (pygeos.points(0, 0.5), [0]), # point at shared vertex between 2 lines (pygeos....
assert_array_equal(line_tree.query(geometry), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line (pygeos.points(0, 0.5), [0]), # point at shared vertex between 2 lines (pygeos....
251
78
263
251
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_lines
test_query_lines
158
177
158
176
7b2d3e1a790e9f3498709303316feee4d0cd88ed
bigcode/the-stack
train
065fa0df0730ad546fcf92fb
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,return_distance,expected", [(None, False, [[], []]), ([None], False, [[], []]), (None, True, ([[], []], []))], ) def test_nearest_all_none(tree, geometry, return_distance, expected): if return_dista...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,return_distance,expected", [(None, False, [[], []]), ([None], False, [[], []]), (None, True, ([[], []], []))], ) def test_nearest_all_none(tree, geometry, return_distance, expected):
if return_distance: index, distance = tree.nearest_all(geometry, return_distance=True) assert_array_equal(index, expected[0]) assert_array_equal(distance, expected[1]) else: assert_array_equal(tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,return_distance,expected", [(None, False, [[], []]), ([None], False, [[], []]), (None, True, ([[], []], []))], ) def test_nearest_all_none(tree, geometry, return_distance, expected):
90
64
147
90
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_none
test_nearest_all_none
1,341
1,353
1,341
1,346
e155652965234a2de46f08102faf373b8e451403
bigcode/the-stack
train
8581907f28c8e6a5d1f04257
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0, 0), [[0], [0]]), (pygeos.points(2, 2), [[0], [2]]), (pygeos.box(0, 5, 1, 6), [[0], [3]]), (pygeos.multipoints([[5, 7], [7, 5]]), [[0], [6]]...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0, 0), [[0], [0]]), (pygeos.points(2, 2), [[0], [2]]), (pygeos.box(0, 5, 1, 6), [[0], [3]]), (pygeos.multipoints([[5, 7], [7, 5]]), [[0], [6]]...
assert_array_equal(poly_tree.nearest(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0, 0), [[0], [0]]), (pygeos.points(2, 2), [[0], [2]]), (pygeos.box(0, 5, 1, 6), [[0], [3]]), (pygeos.multipoints([[5, 7], [7, 5]]), [[0], [6]]...
149
64
162
149
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_polygons
test_nearest_polygons
1,290
1,301
1,290
1,300
0078e9084415d92e4d0ee61430ad670a32c404b2
bigcode/the-stack
train
c63afd5108d7f1093635bc44
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point does not overlap any polygons (different dimensions) (pygeos.points(0, 0), []), # box overlaps 2 polygons (box(0, 0, 1, 1), [0, 1]), # larger box intersects 3 polygons and contains one (box(0, 0, 2, 2), [0, ...
@pytest.mark.parametrize( "geometry,expected", [ # point does not overlap any polygons (different dimensions) (pygeos.points(0, 0), []), # box overlaps 2 polygons (box(0, 0, 1, 1), [0, 1]), # larger box intersects 3 polygons and contains one (box(0, 0, 2, 2), [0, ...
assert_array_equal(poly_tree.query(geometry, predicate="overlaps"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point does not overlap any polygons (different dimensions) (pygeos.points(0, 0), []), # box overlaps 2 polygons (box(0, 0, 1, 1), [0, 1]), # larger box intersects 3 polygons and contains one (box(0, 0, 2, 2), [0, ...
244
78
261
244
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_overlaps_polygons
test_query_overlaps_polygons
529
547
529
546
97b8bf3530933a9e5372cb42740ae8e38c6a4613
bigcode/the-stack
train
20373007b5c383730826b791
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points intersect but not valid relation (pygeos.points(1, 1), []), # all points of result from tree are in common with box (box(3, 3, 6, 6), []), # all points of result from tree are in common with buffer (pygeos....
@pytest.mark.parametrize( "geometry,expected", [ # points intersect but not valid relation (pygeos.points(1, 1), []), # all points of result from tree are in common with box (box(3, 3, 6, 6), []), # all points of result from tree are in common with buffer (pygeos....
assert_array_equal(tree.query(geometry, predicate="crosses"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points intersect but not valid relation (pygeos.points(1, 1), []), # all points of result from tree are in common with box (box(3, 3, 6, 6), []), # all points of result from tree are in common with buffer (pygeos....
153
64
169
153
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_crosses_points
test_query_crosses_points
553
567
553
566
08483181b0cbaadaec9d2635deca381bad656da5
bigcode/the-stack
train
1b9d7fcbf056787c06655f2a
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # 2 polygons in tree overlap point (pygeos.points(0.5, 0.5), [0, 1]), # box ...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # 2 polygons in tree overlap point (pygeos.points(0.5, 0.5), [0, 1]), # box ...
result = poly_tree.nearest(geometry) assert result[1] in expected
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.xfail(reason="equidistant geometries may produce nondeterministic results") @pytest.mark.parametrize( "geometry,expected", [ # 2 polygons in tree overlap point (pygeos.points(0.5, 0.5), [0, 1]), # box ...
337
106
356
337
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_polygons_equidistant
test_nearest_polygons_equidistant
1,304
1,325
1,304
1,323
6d63cc588156a13a4e961801b2429c131f0573f3
bigcode/the-stack
train
2204d6d8dfec14da47daa4a3
train
function
def test_query_tree_with_none(): # valid GEOS binary predicate, but not supported for query tree = pygeos.STRtree( [pygeos.Geometry("POINT (0 0)"), None, pygeos.Geometry("POINT (2 2)")] ) assert tree.query(pygeos.points(2, 2), predicate="intersects") == [2]
def test_query_tree_with_none(): # valid GEOS binary predicate, but not supported for query
tree = pygeos.STRtree( [pygeos.Geometry("POINT (0 0)"), None, pygeos.Geometry("POINT (2 2)")] ) assert tree.query(pygeos.points(2, 2), predicate="intersects") == [2]
_predicate(tree): # valid GEOS binary predicate, but not supported for query with pytest.raises(ValueError): tree.query(pygeos.points(1, 1), predicate="disjoint") def test_query_tree_with_none(): # valid GEOS binary predicate, but not supported for query
64
64
84
21
43
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_tree_with_none
test_query_tree_with_none
214
219
214
215
19f6bbe24743f8fc4d064126f65d7c4446ace6e0
bigcode/the-stack
train
5746a720040dab04432e196f
train
function
@pytest.mark.parametrize("geometry", [empty, empty_point, empty_line_string]) def test_query_empty(tree, geometry): assert tree.query(geometry).size == 0
@pytest.mark.parametrize("geometry", [empty, empty_point, empty_line_string]) def test_query_empty(tree, geometry):
assert tree.query(geometry).size == 0
test_query_invalid_geometry(tree): with pytest.raises(TypeError): tree.query("I am not a geometry") def test_query_none(tree): assert tree.query(None).size == 0 @pytest.mark.parametrize("geometry", [empty, empty_point, empty_line_string]) def test_query_empty(tree, geometry):
64
64
36
24
39
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_empty
test_query_empty
117
119
117
118
9570aeb27d6dc36ec9b5c4bae95e463d41fe8765
bigcode/the-stack
train
77a2b59b5a2b02a09f7200b1
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []), # point at shared vertex between 2 ...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []), # point at shared vertex between 2 ...
assert_array_equal(line_tree.query(geometry, predicate="intersects"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), (pygeos.points(0.5, 0.5), [0]), # point within envelope of first line but does not intersect (pygeos.points(0, 0.5), []), # point at shared vertex between 2 ...
306
96
323
306
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_intersects_lines
test_query_intersects_lines
270
293
270
292
af1afcd800bba8f195a0829157d40dc558872bdb
bigcode/the-stack
train
16fc45a1d081f832d92a2dff
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_all_nonscalar_max_distance(tree): with pytest.raises(ValueError, match="parameter only accepts scalar values"): tree.nearest_all(pygeos.points(0.5, 0.5), max_distance=[1])
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_all_nonscalar_max_distance(tree):
with pytest.raises(ValueError, match="parameter only accepts scalar values"): tree.nearest_all(pygeos.points(0.5, 0.5), max_distance=[1])
max_distance must be greater than 0"): tree.nearest_all(geometry, max_distance=max_distance) @pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") def test_nearest_all_nonscalar_max_distance(tree):
64
64
81
42
22
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_nonscalar_max_distance
test_nearest_all_nonscalar_max_distance
1,473
1,476
1,473
1,474
2ebd7bd82582150be3dca0fafca52a7a743bff7e
bigcode/the-stack
train
dc550d44c8b71e419e7d9926
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry", ["I am not a geometry"]) def test_nearest_all_invalid_geom(tree, geometry): with pytest.raises(TypeError): tree.nearest_all(geometry)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry", ["I am not a geometry"]) def test_nearest_all_invalid_geom(tree, geometry):
with pytest.raises(TypeError): tree.nearest_all(geometry)
(tree.nearest_all(point), [[], []]) @pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize("geometry", ["I am not a geometry"]) def test_nearest_all_invalid_geom(tree, geometry):
64
64
69
54
10
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_invalid_geom
test_nearest_all_invalid_geom
1,334
1,338
1,334
1,336
bfaf6c72c6c17a5c35bd2dbb3e523682ee203836
bigcode/the-stack
train
4edc55e6e319127b5124626a
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any polygons (not valid relation) (pygeos.points(0, 0), []), # line intersects multiple polygons but does not contain any (not valid relation) (pygeos.linestrings([[0, 0], [2, 2]]), []), # box overl...
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any polygons (not valid relation) (pygeos.points(0, 0), []), # line intersects multiple polygons but does not contain any (not valid relation) (pygeos.linestrings([[0, 0], [2, 2]]), []), # box overl...
assert_array_equal( poly_tree.query(geometry, predicate="contains_properly"), expected )
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any polygons (not valid relation) (pygeos.points(0, 0), []), # line intersects multiple polygons but does not contain any (not valid relation) (pygeos.linestrings([[0, 0], [2, 2]]), []), # box overl...
281
91
304
281
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_contains_properly_polygons
test_query_contains_properly_polygons
902
925
902
922
5ed155f4dcb9fbfd58313a24b1eeeff5128098ba
bigcode/the-stack
train
0767b9ba63ca342dfb367d4b
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point covered by polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), (pygeos.points(1, 1), [1]), # midpoint between two polygons is covered by both (pygeos.points(0.5, 0.5), [0, 1]), # line...
@pytest.mark.parametrize( "geometry,expected", [ # point covered by polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), (pygeos.points(1, 1), [1]), # midpoint between two polygons is covered by both (pygeos.points(0.5, 0.5), [0, 1]), # line...
assert_array_equal(poly_tree.query(geometry, predicate="covered_by"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point covered by polygon (pygeos.points(0, 0.5), [0]), (pygeos.points(0.5, 0), [0]), (pygeos.points(1, 1), [1]), # midpoint between two polygons is covered by both (pygeos.points(0.5, 0.5), [0, 1]), # line...
489
151
506
489
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_covered_by_polygons
test_query_covered_by_polygons
807
839
807
838
7ee6d6acf05c99ddd37856387e48544d8234b542
bigcode/the-stack
train
061642b3697457c70abfc8b5
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), # point is within line (pygeos.points(0.5, 0.5), []), # point at shared vertex between 2 lines (pygeos.points(1, 1), [0, 1]), # box overlaps envelope...
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), # point is within line (pygeos.points(0.5, 0.5), []), # point at shared vertex between 2 lines (pygeos.points(1, 1), [0, 1]), # box overlaps envelope...
assert_array_equal(line_tree.query(geometry, predicate="touches"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point intersects first line (pygeos.points(0, 0), [0]), # point is within line (pygeos.points(0.5, 0.5), []), # point at shared vertex between 2 lines (pygeos.points(1, 1), [0, 1]), # box overlaps envelope...
305
96
322
305
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_touches_lines
test_query_touches_lines
631
654
631
653
35a7c1d7eb9c323ac254d836da0c7f2755d3b77a
bigcode/the-stack
train
b93332379214bdf7a8090d28
train
function
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.25, 0.25), [[0], [0]]), (pygeos.points(0.75, 0.75), [[0], [1]]), (pygeos.points(1, 1), [[0], [1]]), # 2 equidistant points in tree (...
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.25, 0.25), [[0], [0]]), (pygeos.points(0.75, 0.75), [[0], [1]]), (pygeos.points(1, 1), [[0], [1]]), # 2 equidistant points in tree (...
assert_array_equal(tree.nearest_all(geometry), expected)
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") @pytest.mark.parametrize( "geometry,expected", [ (pygeos.points(0.25, 0.25), [[0], [0]]), (pygeos.points(0.75, 0.75), [[0], [1]]), (pygeos.points(1, 1), [[0], [1]]), # 2 equidistant points in tree (...
580
177
593
580
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_nearest_all_points
test_nearest_all_points
1,364
1,390
1,364
1,389
9d5d1bb1c13f0bc2c7508b0f9015f02097ff612d
bigcode/the-stack
train
43f2dc1494d7bbc61e1a5a04
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # line contains every point that is not on its first or last coordinate # these are on the "exterior" of the li...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # line contains every point that is not on its first or last coordinate # these are on the "exterior" of the li...
assert_array_equal(tree.query(geometry, predicate="contains_properly"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect (pygeos.points(0.5, 0.5), []), # points intersect (pygeos.points(1, 1), [1]), # line contains every point that is not on its first or last coordinate # these are on the "exterior" of the li...
441
137
459
441
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_contains_properly_points
test_query_contains_properly_points
843
874
843
873
fc80083ef03f484336e8f2ddfa223232c0d97da1
bigcode/the-stack
train
c85109d479fc44961b9df934
train
function
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect ([pygeos.points(0.5, 0.5)], [[], []]), # points intersect ([pygeos.points(1, 1)], [[0], [1]]), # box contains points ([box(3, 3, 6, 6)], [[0, 0, 0, 0], [3, 4, 5, 6]]), # first and l...
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect ([pygeos.points(0.5, 0.5)], [[], []]), # points intersect ([pygeos.points(1, 1)], [[0], [1]]), # box contains points ([box(3, 3, 6, 6)], [[0, 0, 0, 0], [3, 4, 5, 6]]), # first and l...
assert_array_equal(tree.query_bulk(geometry, predicate="intersects"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # points do not intersect ([pygeos.points(0.5, 0.5)], [[], []]), # points intersect ([pygeos.points(1, 1)], [[0], [1]]), # box contains points ([box(3, 3, 6, 6)], [[0, 0, 0, 0], [3, 4, 5, 6]]), # first and l...
492
152
509
492
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_bulk_intersects_points
test_query_bulk_intersects_points
1,077
1,117
1,077
1,116
d4c5d206d88babc54a89ebf6123bf4aee111ba35
bigcode/the-stack
train
837932e330fb25eaed14312f
train
function
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any polygons (not valid relation) (pygeos.points(0, 0), []), # box overlaps envelope of 2 polygons but contains neither (box(0, 0, 1, 1), []), # larger box intersects 3 polygons but contains only on...
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any polygons (not valid relation) (pygeos.points(0, 0), []), # box overlaps envelope of 2 polygons but contains neither (box(0, 0, 1, 1), []), # larger box intersects 3 polygons but contains only on...
assert_array_equal(poly_tree.query(geometry, predicate="contains"), expected)
@pytest.mark.parametrize( "geometry,expected", [ # point does not contain any polygons (not valid relation) (pygeos.points(0, 0), []), # box overlaps envelope of 2 polygons but contains neither (box(0, 0, 1, 1), []), # larger box intersects 3 polygons but contains only on...
239
76
255
239
0
snowman2/pygeos
pygeos/tests/test_strtree.py
Python
test_query_contains_polygons
test_query_contains_polygons
456
475
456
474
374bcf07f2edc8d1f894ecaa433a3afa73f88a1a
bigcode/the-stack
train
9ac6c0021c9f37a980ad03cf
train
class
class MainApp(App): def build(self): return root
class MainApp(App):
def build(self): return root
1 Rectangle: pos: self.pos size: self.size Button: text: 'Hello World' size_hint: .5, .5 pos_hint: {'center_x':0.5, 'center_y':0.5} ''') class MainApp(App):
64
64
14
5
59
xiaobojiang/kivy_playground
app/basic_kv.py
Python
MainApp
MainApp
23
25
23
23
e06e609bb328d89d6e75f3cb3f5896f9d7a7e934
bigcode/the-stack
train
a1346845d5e768b0d44ad269
train
class
class CheckoutView(LoginRequiredMixin, FormView): template_name = "store/checkout.html" form_class = CheckoutForm success_url = reverse_lazy("home") def get_form_kwargs(self): kwargs = super(CheckoutView, self).get_form_kwargs() kwargs.update({'user': self.request.user}) return kwargs
class CheckoutView(LoginRequiredMixin, FormView):
template_name = "store/checkout.html" form_class = CheckoutForm success_url = reverse_lazy("home") def get_form_kwargs(self): kwargs = super(CheckoutView, self).get_form_kwargs() kwargs.update({'user': self.request.user}) return kwargs
object_list = list(Cart(self.request)) return object_list def get_context_data(self, **kwargs): context = super(CartView, self).get_context_data(**kwargs) context["cart"] = Cart(self.request) return context class CheckoutView(LoginRequiredMixin, FormView):
64
64
69
10
53
rafaellima47/django-ecommerce
store/views.py
Python
CheckoutView
CheckoutView
76
84
76
76
c576df56ca072215ea47b76b3dfae59596ffedef
bigcode/the-stack
train
08f9d138f7898861a52546d5
train
function
@login_required def update_wishlist(request, pk): customer = request.user product = get_object_or_404(Product, pk=pk) try: item = WishlistItem.objects.get(customer=customer, product=product) item.delete() except WishlistItem.DoesNotExist: item = WishlistItem(customer=customer, product=product) item.save() ...
@login_required def update_wishlist(request, pk):
customer = request.user product = get_object_or_404(Product, pk=pk) try: item = WishlistItem.objects.get(customer=customer, product=product) item.delete() except WishlistItem.DoesNotExist: item = WishlistItem(customer=customer, product=product) item.save() return HttpResponseRedirect(request.META.get('HT...
self.get_ordering(object_list, ordering) return object_list def get_context_data(self, **kwargs): context = super(SearchView, self).get_context_data(**kwargs) context["categories_list"] = Category.objects.all() return context @login_required def update_wishlist(request, pk):
64
64
89
11
52
rafaellima47/django-ecommerce
store/views.py
Python
update_wishlist
update_wishlist
184
196
184
185
f4f3ad0021d937f7412c0581a49f180a35ff033d
bigcode/the-stack
train
b83446750e14060ae34af2a2
train
class
class CartView(ListView): template_name = "store/cart.html" def get_queryset(self): object_list = list(Cart(self.request)) return object_list def get_context_data(self, **kwargs): context = super(CartView, self).get_context_data(**kwargs) context["cart"] = Cart(self.request) return context
class CartView(ListView):
template_name = "store/cart.html" def get_queryset(self): object_list = list(Cart(self.request)) return object_list def get_context_data(self, **kwargs): context = super(CartView, self).get_context_data(**kwargs) context["cart"] = Cart(self.request) return context
.POST) if form.is_valid: review = form.save(commit=False) review.customer = request.user review.product = self.get_object() review.save() product.rate = self.update_avg_rate() product.save() return self.get(request) class CartView(ListView):
64
64
73
6
58
rafaellima47/django-ecommerce
store/views.py
Python
CartView
CartView
63
73
63
63
33616e3e0004d98fb03ab58c1f394a95f24c6d25
bigcode/the-stack
train
a6599f84ca1ed0af4d009502
train
class
class ProductDetailView(DetailView): template_name = "store/product_detail.html" model = Product def update_avg_rate(self): product = self.get_object() avg = 0 rates = Review.objects.filter(product=product).values("rate") for value in rates: avg += value["rate"] if avg == 0: return avg return avg/...
class ProductDetailView(DetailView):
template_name = "store/product_detail.html" model = Product def update_avg_rate(self): product = self.get_object() avg = 0 rates = Review.objects.filter(product=product).values("rate") for value in rates: avg += value["rate"] if avg == 0: return avg return avg/len(rates) def get_context_data(sel...
View, View, RedirectView, CreateView import stripe from .models import Product, Category, WishlistItem, Order, OrderItem, ShippingInformation, Review from .cart import Cart from .forms import ShippingInformationForm, CheckoutForm, ProductReviewForm class HomeView(ListView): template_name = "store/home.html" query...
84
84
283
8
76
rafaellima47/django-ecommerce
store/views.py
Python
ProductDetailView
ProductDetailView
23
60
23
23
d9ac110fd6394f7c9425bd2d0f60fdae1181685f
bigcode/the-stack
train
8ad9fad43441e34c7480b4d7
train
class
class SearchView(ListView): template_name = "store/search.html" model = Product paginate_by = 10 def get_ordering(self, queryset, ordering): """ Return an ordered queryset according to the ordering option chosen """ if ordering == "1": pass # Highest Rate elif ordering == "2": return queryset.ord...
class SearchView(ListView):
template_name = "store/search.html" model = Product paginate_by = 10 def get_ordering(self, queryset, ordering): """ Return an ordered queryset according to the ordering option chosen """ if ordering == "1": pass # Highest Rate elif ordering == "2": return queryset.order_by("price") elif orderi...
stripe_checkout_webhook/", cancel_url=f"http://localhost:8000/", ) return HttpResponseRedirect(checkout_session.url) class OrdersHistory(ListView): template_name = "store/history.html" def get_queryset(self): return Order.objects.filter(customer=self.request.user) class AccountPageView(LoginRequired...
84
84
282
6
78
rafaellima47/django-ecommerce
store/views.py
Python
SearchView
SearchView
136
181
136
136
49f000e26dcf88bd68f3479926c39a56c0974dae
bigcode/the-stack
train
201d3a206a27c4832012715d
train
function
def stripe_checkout_webhook(request): shipping_info = ShippingInformation.objects.filter(customer=request.user)[0] order = Order(customer=request.user, shipping_info=shipping_info) order.save() cart = request.session.get("cart") for item in cart: product = Product.objects.get(pk=item) OrderItem.objects.crea...
def stripe_checkout_webhook(request):
shipping_info = ShippingInformation.objects.filter(customer=request.user)[0] order = Order(customer=request.user, shipping_info=shipping_info) order.save() cart = request.session.get("cart") for item in cart: product = Product.objects.get(pk=item) OrderItem.objects.create( order=order, product=prod...
override_quantity) return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) @require_POST def cart_delete(request, pk): cart = Cart(request) cart.delete(pk) return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) def stripe_checkout_webhook(request):
63
64
105
7
56
rafaellima47/django-ecommerce
store/views.py
Python
stripe_checkout_webhook
stripe_checkout_webhook
220
234
220
220
955402a6aec31f4920bfbffd98a95b197445bba6
bigcode/the-stack
train
ed10d09ca42d1ebfb5d178af
train
class
class OrdersHistory(ListView): template_name = "store/history.html" def get_queryset(self): return Order.objects.filter(customer=self.request.user)
class OrdersHistory(ListView):
template_name = "store/history.html" def get_queryset(self): return Order.objects.filter(customer=self.request.user)
ayment_method_types=["card"], mode="payment", line_items=line_items, success_url=f"http://localhost:8000/stripe_checkout_webhook/", cancel_url=f"http://localhost:8000/", ) return HttpResponseRedirect(checkout_session.url) class OrdersHistory(ListView):
64
64
29
6
58
rafaellima47/django-ecommerce
store/views.py
Python
OrdersHistory
OrdersHistory
125
129
125
125
a185ba6056c1d72edd8a1ca81e1426ba20347eb2
bigcode/the-stack
train
44ff10f6ce6d6f8800aafe61
train
class
class StripeCheckoutView(LoginRequiredMixin, View): def post(self, request, *args, **kwargs): stripe.api_key = settings.STRIPE_SECRET_KEY cart = request.session.get("cart") line_items = [] for item in cart: product = Product.objects.get(pk=item) line_items.append({ "name": product.title, "qu...
class StripeCheckoutView(LoginRequiredMixin, View):
def post(self, request, *args, **kwargs): stripe.api_key = settings.STRIPE_SECRET_KEY cart = request.session.get("cart") line_items = [] for item in cart: product = Product.objects.get(pk=item) line_items.append({ "name": product.title, "quantity": cart[item]["quantity"], "currency": "brl...
_info.html" form_class = ShippingInformationForm def form_valid(self, form): shipping_info = form.save(commit=False) shipping_info.customer = self.request.user shipping_info.save() return HttpResponseRedirect(reverse("checkout")) class StripeCheckoutView(LoginRequiredMixin, View):
63
64
182
11
52
rafaellima47/django-ecommerce
store/views.py
Python
StripeCheckoutView
StripeCheckoutView
98
122
98
99
4686d8f60db3a6bd0bcf3281a18aa75d67ea6dc0
bigcode/the-stack
train
54e72dd03c8a3b64c86cccb2
train
class
class ShippingInformationView(LoginRequiredMixin, FormView): template_name = "store/shipping_info.html" form_class = ShippingInformationForm def form_valid(self, form): shipping_info = form.save(commit=False) shipping_info.customer = self.request.user shipping_info.save() return HttpResponseRedirect(revers...
class ShippingInformationView(LoginRequiredMixin, FormView):
template_name = "store/shipping_info.html" form_class = ShippingInformationForm def form_valid(self, form): shipping_info = form.save(commit=False) shipping_info.customer = self.request.user shipping_info.save() return HttpResponseRedirect(reverse("checkout"))
checkout.html" form_class = CheckoutForm success_url = reverse_lazy("home") def get_form_kwargs(self): kwargs = super(CheckoutView, self).get_form_kwargs() kwargs.update({'user': self.request.user}) return kwargs class ShippingInformationView(LoginRequiredMixin, FormView):
64
64
70
11
52
rafaellima47/django-ecommerce
store/views.py
Python
ShippingInformationView
ShippingInformationView
87
95
87
87
96996338f2f4bd52cb97782ad249b6a277ab7cc8
bigcode/the-stack
train