def test_datetime_series_binops_numpy(lhs_dtype, rhs_dtype): pd_data_1 = pd.Series( pd.date_range("20010101", "20020215", freq="400h", name="times")) pd_data_2 = pd.Series( pd.date_range("20010101", "20020215", freq="401h", name="times")) gdf_data_1 = Series(pd_data_1).astype(lhs_dtype) gdf_data_2 = Series(pd_data_2).astype(rhs_dtype) np_data_1 = np.array(pd_data_1).astype(lhs_dtype) np_data_2 = np.array(pd_data_2).astype(rhs_dtype) np.testing.assert_equal(np_data_1, gdf_data_1.to_array()) np.testing.assert_equal(np_data_2, gdf_data_2.to_array()) np.testing.assert_equal(np.less(np_data_1, np_data_2), (gdf_data_1 < gdf_data_2).to_array()) np.testing.assert_equal(np.greater(np_data_1, np_data_2), (gdf_data_1 > gdf_data_2).to_array()) np.testing.assert_equal(np.equal(np_data_1, np_data_2), (gdf_data_1 == gdf_data_2).to_array()) np.testing.assert_equal( np.less_equal(np_data_1, np_data_2), (gdf_data_1 <= gdf_data_2).to_array(), ) np.testing.assert_equal( np.greater_equal(np_data_1, np_data_2), (gdf_data_1 >= gdf_data_2).to_array(), )
def test_series_argsort(nelem, dtype, asc): np.random.seed(0) sr = Series((100 * np.random.random(nelem)).astype(dtype)) res = sr.argsort(ascending=asc) if asc: expected = np.argsort(sr.to_array(), kind="mergesort") else: expected = np.argsort(sr.to_array() * -1, kind="mergesort") np.testing.assert_array_equal(expected, res.to_array())
def test_series_sort_index(nelem, asc): np.random.seed(0) sr = Series((100 * np.random.random(nelem))) orig = sr.to_array() got = sr.sort_values().sort_index(ascending=asc).to_array() if not asc: # Reverse the array for descending sort got = got[::-1] np.testing.assert_array_equal(orig, got)
plyreader = shapefile.Reader("NYC_boroughs.shp") polygons = plyreader.shapes() plys = [] for ply in polygons: plys.append(shape(ply)) start = time.time() bm1 = cpp_point_in_polygon_bitmap(x1, y1, NYC_gpu[0], NYC_gpu[1], NYC_gpu[2]['x'], NYC_gpu[2]['y']) bm2 = cpp_point_in_polygon_bitmap(x2, y2, NYC_gpu[0], NYC_gpu[1], NYC_gpu[2]['x'], NYC_gpu[2]['y']) end = time.time() print("Python GPU Time in ms (end-to-end)={}".format((end - start) * 1000)) bm1a = bm1.to_array() pntx = x1.to_array() pnty = y1.to_array() start = time.time() mis_match = 0 #for i in range(len(pntx)): for i in range(10000): pt = Point(pntx[i], pnty[i]) res = 0 for j in range(len(plys)): pip = plys[len(plys) - 1 - j].contains(pt) if pip: res |= 0x01 << (len(plys) - 1 - j) #print("cpu={}, gpu={}".format(res,bm1a[i])) #print("{},{},{},{}".format(pntx[i], pnty[i],bm1a[i],res)) if res != bm1a[i]:
def test_typecast_to_different_datetime_resolutions(data, dtype): pd_data = pd.Series(data.copy()) np_data = np.array(pd_data).astype(dtype) gdf_series = Series(pd_data).astype(dtype) np.testing.assert_equal(np_data, gdf_series.to_array())