nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: OceanParcels/parcels
Pull request #525 (2019-01-29 09:12:15)

Raising an error for Variable.name='z'
As ‘z’ is used in ParticleFile for particle.depth (from CF-convention), it shouldn’t also be used for a custom Variable. This PR raises an error when user specifies a custom Variable with name 'z'


Patch:
diff --git a/parcels/particle.py b/parcels/particle.py
index a68ad675..4fd61f0e 100644
--- a/parcels/particle.py
+++ b/parcels/particle.py
@@ -21,6 +21,8 @@ class Variable(object):
     :param to_write: Boolean to control whether Variable is written to NetCDF file
     """
     def __init__(self, name, dtype=np.float32, initial=0, to_write=True):
+        if name == 'z':
+            raise NotImplementedError("Custom Variable name 'z' is not allowed, as it is used for depth in ParticleFile")
         self.name = name
         self.dtype = dtype
         self.initial = initial


Test patch:
diff --git a/tests/test_particles.py b/tests/test_particles.py
index 7b7be79a..2bdb64fc 100644
--- a/tests/test_particles.py
+++ b/tests/test_particles.py
@@ -51,6 +51,19 @@ def test_variable_unsupported_dtypes(fieldset, mode, type):
     assert error_thrown
 
 
+@pytest.mark.parametrize('mode', ['scipy', 'jit'])
+def test_variable_special_names(fieldset, mode):
+    """Test that checks errors thrown for special names"""
+    class TestParticle(ptype[mode]):
+        error_thrown = False
+        try:
+            z = Variable('z', dtype=np.float32, initial=10.)
+        except RuntimeError:
+            error_thrown = True
+        assert error_thrown
+    ParticleSet(fieldset, pclass=TestParticle, lon=[0], lat=[0])
+
+
 @pytest.mark.parametrize('mode', ['scipy', 'jit'])
 def test_variable_init_relative(fieldset, mode, npart=10):
     """Test that checks relative initialisation of custom variables"""
Repository: trustwallet/blockatlas
Pull request #891 (2020-02-19 03:36:11)

Add support for rpc batch call
closes https://github.com/trustwallet/blockatlas/issues/889


Patch:
diff --git a/pkg/blockatlas/jsonrpc.go b/pkg/blockatlas/jsonrpc.go
index bc01f3d..e250fbd 100644
--- a/pkg/blockatlas/jsonrpc.go
+++ b/pkg/blockatlas/jsonrpc.go
@@ -9,6 +9,8 @@ const (
 	JsonRpcVersion = "2.0"
 )
 
+type RpcRequests []*RpcRequest
+
 type RpcRequest struct {
 	JsonRpc string      `json:"jsonrpc"`
 	Method  string      `json:"method"`
@@ -56,3 +58,20 @@ func (r *Request) RpcCall(result interface{}, method string, params interface{})
 	}
 	return resp.GetObject(result)
 }
+
+func (r *Request) RpcBatchCall(requests RpcRequests) ([]RpcResponse, error) {
+	var resp []RpcResponse
+	err := r.Post(&resp, "", requests.fillDefaultValues())
+	if err != nil {
+		return nil, err
+	}
+	return resp, nil
+}
+
+func (rs RpcRequests) fillDefaultValues() RpcRequests {
+	for _, r := range rs {
+		r.JsonRpc = JsonRpcVersion
+		r.Id = r.Method
+	}
+	return rs
+}


Test patch:
diff --git a/pkg/blockatlas/jsonrpc_test.go b/pkg/blockatlas/jsonrpc_test.go
new file mode 100644
index 0000000..b954175
--- /dev/null
+++ b/pkg/blockatlas/jsonrpc_test.go
@@ -0,0 +1,34 @@
+package blockatlas
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestRpcRequests_fillDefaultValues(t *testing.T) {
+	tests := []struct {
+		name string
+		rs   RpcRequests
+		want RpcRequests
+	}{
+		{
+			"test 1",
+			RpcRequests{{Method: "method1", Params: "params1"}},
+			RpcRequests{{Method: "method1", Params: "params1", JsonRpc: JsonRpcVersion, Id: "method1"}},
+		}, {
+			"test 2",
+			RpcRequests{
+				{Method: "method1", Params: "params1"}, {Method: "method2", Params: "params2"}},
+			RpcRequests{
+				{Method: "method1", Params: "params1", JsonRpc: JsonRpcVersion, Id: "method1"},
+				{Method: "method2", Params: "params2", JsonRpc: JsonRpcVersion, Id: "method2"},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			got := tt.rs.fillDefaultValues()
+			assert.Equal(t, tt.want, got)
+		})
+	}
+}