nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: valyala/fasthttp
Pull request #505 (2018-12-29 13:22:25)

add method Sort in args
sorted args string is useful in cache key。

xuecai: 
in your meas , it use like this ?
```
args := fasthttp.AcquireArgs()
// do something 

args.Sort() // just AppendBytesSort, it call sort.SliceStable and AppendBytes
cachekey := args.QueryString()  // call AppendBytes 
```

AppendBytesSort  do sort Args.args and rewrite Args.buf call AppendBytes
String and QueryString also call AppendBytes.
AppendBytes called twice is necessary ?
erikdubbelboer: Yes that is exactly what I mean. `Sort` should only do the sorting and have no argument or return value. That wat it's clear that you're changing the data by calling `Sort`. Right now it's not clear that you're changing the underlying data by calling `AppendBytesSort` for example.
xuecai: done , only Sort method add.
btw, Sort cost 3 allocs/op.
erikdubbelboer: Looks good. Any comments @kirillDanshin ?
xuecai: @kirillDanshin   any comments?  my parterner want to use this feature . tks.

Patch:
diff --git a/args.go b/args.go
index 8b67f90..dc1a73d 100644
--- a/args.go
+++ b/args.go
@@ -4,13 +4,14 @@ import (
 	"bytes"
 	"errors"
 	"io"
+	"sort"
 	"sync"
 
 	"github.com/valyala/bytebufferpool"
 )
 
 const (
-	argsNoValue = true
+	argsNoValue  = true
 	argsHasValue = false
 )
 
@@ -115,6 +116,19 @@ func (a *Args) QueryString() []byte {
 	return a.buf
 }
 
+// Sort sorts Args by key and then value using 'f' as comparison function.
+//
+// For example args.Sort(bytes.Compare)
+func (a *Args) Sort(f func(x, y []byte) int) {
+	sort.SliceStable(a.args, func(i, j int) bool {
+		n := f(a.args[i].key, a.args[j].key)
+		if n == 0 {
+			return f(a.args[i].value, a.args[j].value) == -1
+		}
+		return n == -1
+	})
+}
+
 // AppendBytes appends query string to dst and returns the extended dst.
 func (a *Args) AppendBytes(dst []byte) []byte {
 	for i, n := 0, len(a.args); i < n; i++ {


Test patch:
diff --git a/args_test.go b/args_test.go
index 2a5cb9a..db44750 100644
--- a/args_test.go
+++ b/args_test.go
@@ -1,6 +1,7 @@
 package fasthttp
 
 import (
+	"bytes"
 	"fmt"
 	"reflect"
 	"strings"
@@ -48,6 +49,13 @@ func TestArgsAdd(t *testing.T) {
 		t.Fatalf("unexpected result: %q. Expecting %q", s, expectedS)
 	}
 
+	a.Sort(bytes.Compare)
+	ss := a.String()
+	expectedSS := "ba=23&foo=&foo&foo=1&foo=bar&foo=baz"
+	if ss != expectedSS {
+		t.Fatalf("unexpected result: %q. Expecting %q", ss, expectedSS)
+	}
+
 	var a1 Args
 	a1.Parse(s)
 	if a1.Len() != 6 {
Repository: valyala/fasthttp
Pull request #649 (2019-09-09 22:26:39)

Added option to disable path normalization

erikdubbelboer: Can you explain why you need this/why this is useful? Also can you add some tests that show this works?
dfirsht: Added a test to show path normalization being disabled.

This is helpful for proxy servers that wish to preserve the original path when forwarding requests. With this option, the proxy server will not make any assumptions on how the destination server expects paths to be formatted and instead, can let that server do its own normalization.
dfirsht: To more closely align with options like `DisableHeaderNamesNormalizing`, I made the `DisablePathNormalizing` bool an exported member. If you prefer though, I can add back the method instead.

Patch:
diff --git a/uri.go b/uri.go
index e9cd4b1..913c86b 100644
--- a/uri.go
+++ b/uri.go
@@ -48,6 +48,15 @@ type URI struct {
 	queryArgs       Args
 	parsedQueryArgs bool
 
+	// Path values are sent as-is without normalization
+	//
+	// Disabled path normalization may be useful for proxying incoming requests
+	// to servers that are expecting paths to be forwarded as-is.
+	//
+	// By default path values are normalized, i.e.
+	// extra slashes are removed, special characters are encoded.
+	DisablePathNormalizing bool
+
 	fullURI    []byte
 	requestURI []byte
 
@@ -71,6 +80,7 @@ func (u *URI) CopyTo(dst *URI) {
 
 	u.queryArgs.CopyTo(&dst.queryArgs)
 	dst.parsedQueryArgs = u.parsedQueryArgs
+	dst.DisablePathNormalizing = u.DisablePathNormalizing
 
 	// fullURI and requestURI shouldn't be copied, since they are created
 	// from scratch on each FullURI() and RequestURI() call.
@@ -215,6 +225,7 @@ func (u *URI) Reset() {
 	u.host = u.host[:0]
 	u.queryArgs.Reset()
 	u.parsedQueryArgs = false
+	u.DisablePathNormalizing = false
 
 	// There is no need in u.fullURI = u.fullURI[:0], since full uri
 	// is calculated on each call to FullURI().
@@ -387,7 +398,12 @@ func normalizePath(dst, src []byte) []byte {
 
 // RequestURI returns RequestURI - i.e. URI without Scheme and Host.
 func (u *URI) RequestURI() []byte {
-	dst := appendQuotedPath(u.requestURI[:0], u.Path())
+	var dst []byte
+	if u.DisablePathNormalizing {
+		dst = append(u.requestURI[:0], u.PathOriginal()...)
+	} else {
+		dst = appendQuotedPath(u.requestURI[:0], u.Path())
+	}
 	if u.queryArgs.Len() > 0 {
 		dst = append(dst, '?')
 		dst = u.queryArgs.AppendBytes(dst)


Test patch:
diff --git a/uri_test.go b/uri_test.go
index 7ed05f9..84f9380 100644
--- a/uri_test.go
+++ b/uri_test.go
@@ -184,6 +184,16 @@ func testURIPathNormalize(t *testing.T, u *URI, requestURI, expectedPath string)
 	}
 }
 
+func TestURINoNormalization(t *testing.T) {
+	var u URI
+	irregularPath := "/aaa%2Fbbb%2F%2E.%2Fxxx"
+	u.Parse(nil, []byte(irregularPath))
+	u.DisablePathNormalizing = true
+	if string(u.RequestURI()) != irregularPath {
+		t.Fatalf("Unexpected path %q. Expected %q.", u.Path(), irregularPath)
+	}
+}
+
 func TestURICopyTo(t *testing.T) {
 	var u URI
 	var copyU URI
Repository: valyala/fasthttp
Pull request #859 (2020-08-05 13:39:38)

Add a api `DisableNoDefaultContentType` to disable add default content type.
@valyala Add api DisableNoDefaultContentType to disable default conten type if no `Content-Type` header.


Patch:
diff --git a/header.go b/header.go
index 3917f5c..59d0165 100644
--- a/header.go
+++ b/header.go
@@ -601,10 +601,15 @@ func (h *ResponseHeader) DisableNormalizing() {
 	h.disableNormalizing = true
 }
 
+// SetNoDefaultContentType allows you to control if a default Content-Type header will be set (false) or not (true).
+func (h *ResponseHeader) SetNoDefaultContentType(noDefaultContentType bool) {
+	h.noDefaultContentType = noDefaultContentType
+}
+
 // Reset clears response header.
 func (h *ResponseHeader) Reset() {
 	h.disableNormalizing = false
-	h.noDefaultContentType = false
+	h.SetNoDefaultContentType(false)
 	h.noDefaultDate = false
 	h.resetSkipNormalize()
 }


Test patch:
diff --git a/header_test.go b/header_test.go
index 2ef2750..0fcca30 100644
--- a/header_test.go
+++ b/header_test.go
@@ -1240,7 +1240,7 @@ func TestResponseContentTypeNoDefaultNotEmpty(t *testing.T) {
 
 	var h ResponseHeader
 
-	h.noDefaultContentType = true
+	h.SetNoDefaultContentType(true)
 	h.SetContentLength(5)
 
 	headers := h.String()
@@ -2193,10 +2193,10 @@ func TestResponseHeaderReadSuccess(t *testing.T) {
 		400, 123, string(defaultContentType), "foiaaa")
 
 	// no content-type and no default
-	h.noDefaultContentType = true
+	h.SetNoDefaultContentType(true)
 	testResponseHeaderReadSuccess(t, h, "HTTP/1.1 400 OK\r\nContent-Length: 123\r\n\r\nfoiaaa",
 		400, 123, "", "foiaaa")
-	h.noDefaultContentType = false
+	h.SetNoDefaultContentType(false)
 
 	// no headers
 	testResponseHeaderReadSuccess(t, h, "HTTP/1.1 200 OK\r\n\r\naaaabbb",
Repository: go-go-golems/glazed
Pull request #265 (2023-03-30 05:47:36)

:ambulance: Fix quoted string handling


Patch:
diff --git a/pkg/helpers/yaml/yaml.go b/pkg/helpers/yaml/yaml.go
index 6c070dc..68db284 100644
--- a/pkg/helpers/yaml/yaml.go
+++ b/pkg/helpers/yaml/yaml.go
@@ -48,7 +48,7 @@ func Clean(s string) string {
 			parts := strings.Split(line, ":")
 			if len(parts) > 2 {
 				key := parts[0]
-				value := strings.TrimSpace(parts[1] + ":" + parts[2])
+				value := strings.TrimSpace(strings.Join(parts[1:], ":"))
 
 				// check if value is a quoted string
 				if strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"") ||
@@ -64,6 +64,13 @@ func Clean(s string) string {
 				key := parts[0]
 				value := strings.TrimSpace(parts[1])
 
+				// check if value is a quoted string
+				if strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"") ||
+					strings.HasPrefix(value, "'") && strings.HasSuffix(value, "'") {
+					ret = append(ret, line)
+					continue
+				}
+
 				// check if this is the start of a multine string
 				if strings.HasPrefix(value, "|") {
 					isInQuotedString = true


Test patch:
diff --git a/pkg/helpers/yaml/yaml_test.go b/pkg/helpers/yaml/yaml_test.go
index e746df1..00250ae 100644
--- a/pkg/helpers/yaml/yaml_test.go
+++ b/pkg/helpers/yaml/yaml_test.go
@@ -159,3 +159,20 @@ d: "&lkjsld"
 	actualYAML := Clean(inputYAML)
 	assert.Equal(t, expectedYAML, actualYAML)
 }
+
+func TestQuotedStrings(t *testing.T) {
+	inputYAML := `
+title: "Evergreen Trees - The Tree Center"
+meta_title: "Buy Evergreen Trees Online - Create Year-Round Privacy and Beauty | The Tree Center"
+meta_description: "Shop a variety of evergreen trees that stay green all year at The Tree Center. Create year-round privacy and beauty with our selection of evergreen trees. Find the perfect evergreen for your garden today!"
+`
+
+	expectedYAML := `
+title: "Evergreen Trees - The Tree Center"
+meta_title: "Buy Evergreen Trees Online - Create Year-Round Privacy and Beauty | The Tree Center"
+meta_description: "Shop a variety of evergreen trees that stay green all year at The Tree Center. Create year-round privacy and beauty with our selection of evergreen trees. Find the perfect evergreen for your garden today!"
+`
+
+	actualYAML := Clean(inputYAML)
+	assert.Equal(t, expectedYAML, actualYAML)
+}
Repository: go-go-golems/glazed
Pull request #407 (2024-01-20 15:06:10)

Add NDJSON parsing support for object lists
Enhancements in this pull request:

- Introduced support for loading object lists from NDJSON files.


Patch:
diff --git a/pkg/cmds/parameters/parse.go b/pkg/cmds/parameters/parse.go
index df432de..d3260b7 100644
--- a/pkg/cmds/parameters/parse.go
+++ b/pkg/cmds/parameters/parse.go
@@ -578,6 +578,20 @@ func (p *ParameterDefinition) parseObjectListFromReader(
 			objectList = []interface{}{object}
 		}
 		ret.Update(objectList, options...)
+	} else if strings.HasSuffix(filename, ".ndjson") {
+		scanner := bufio.NewScanner(f)
+		for scanner.Scan() {
+			line := scanner.Text()
+			err := json.Unmarshal([]byte(line), &object)
+			if err != nil {
+				return nil, errors.Wrapf(err, "Could not parse line %s as JSON", line)
+			}
+			objectList = append(objectList, object)
+		}
+		if err := scanner.Err(); err != nil {
+			return nil, err
+		}
+		ret.Update(objectList, options...)
 	} else if strings.HasSuffix(filename, ".yaml") || strings.HasSuffix(filename, ".yml") {
 		b, err := io.ReadAll(f)
 		if err != nil {


Test patch:
diff --git a/pkg/cmds/parameters/parse_test.go b/pkg/cmds/parameters/parse_test.go
index 4c39d4a..cd1afcb 100644
--- a/pkg/cmds/parameters/parse_test.go
+++ b/pkg/cmds/parameters/parse_test.go
@@ -586,6 +586,26 @@ func TestParseObjectListFromFile(t *testing.T) {
 	_, err = parseObjectListFromString(parameter, `["test"]`, "test.json")
 	assert.Error(t, err)
 
+	// now ndjson
+	v, err = parseObjectListFromString(parameter, `{"test":"test"}
+{"test2":"test2"}`, "test.ndjson")
+	require.NoError(t, err)
+	assert.Equal(t, []map[string]interface{}{{"test": "test"}, {"test2": "test2"}}, v)
+
+	// fail on ndjson with no newline
+	_, err = parseObjectListFromString(parameter, `{"test":"test"}{"test2":"test2"}`, "test.ndjson")
+	assert.Error(t, err)
+
+	// ndjson with a single object
+	v, err = parseObjectListFromString(parameter, `{"test":"test"}`, "test.ndjson")
+	require.NoError(t, err)
+	assert.Equal(t, []map[string]interface{}{{"test": "test"}}, v)
+
+	// fail on non object line
+	_, err = parseObjectListFromString(parameter, `{"test":"test"}
+"test"`, "test.ndjson")
+	assert.Error(t, err)
+
 	// now yaml
 	v, err = parseObjectListFromString(parameter, `- test: test`, "test.yaml")
 	require.NoError(t, err)
Repository: JuliaStats/HypothesisTests.jl
Pull request #289 (2023-03-19 11:57:53)

Pearson's Chi-Squared Test with 2 vectors
This commit tries to address issue #277 

- Added Pearson's Chi-Squared Test with 2 vectors of `integer` type
- Added tests for the said function

This commit works on the idea mentioned in [here](https://github.com/JuliaStats/HypothesisTests.jl/issues/277#issuecomment-1192952372).


Patch:
diff --git a/src/power_divergence.jl b/src/power_divergence.jl
index baa2cbf..39f6b84 100644
--- a/src/power_divergence.jl
+++ b/src/power_divergence.jl
@@ -362,6 +362,11 @@ a goodness-of-fit test is performed (`x` is treated as a one-dimensional conting
 table). In this case, the hypothesis tested is whether the population probabilities equal
 those in `theta0`, or are all equal if `theta0` is not given.
 
+If only `y` and `x` are given and both are vectors of integer type, then once again a
+goodness-of-fit test is performed. In this case, `theta0` is calculated by the proportion
+of each individual values in `y`. Here, the hypothesis tested is whether the two samples
+`x` and `y` come from the same population or not.
+
 If `x` is a matrix with at least two rows and columns, it is taken as a two-dimensional
 contingency table. Otherwise, `x` and `y` must be vectors of the same length. The contingency
 table is calculated using `counts` function from the `StatsBase` package. Then the power
@@ -387,6 +392,11 @@ function ChisqTest(x::AbstractVector{T}, y::AbstractVector{T}, k::T) where T<:In
     PowerDivergenceTest(d, lambda=1.0)
 end
 
+function ChisqTest(x::AbstractVector{T}, y::AbstractVector{T}) where {T<:Integer}
+    theta0 = y ./ sum(y)
+    PowerDivergenceTest(reshape(x, length(x), 1), lambda=1.0, theta0=theta0)
+end
+
 ChisqTest(x::AbstractVector{T}, theta0::Vector{U} = ones(length(x))/length(x)) where {T<:Integer,U<:AbstractFloat} =
     PowerDivergenceTest(reshape(x, length(x), 1), lambda=1.0, theta0=theta0)
 


Test patch:
diff --git a/test/power_divergence.jl b/test/power_divergence.jl
index 6c058b0..71c6b2f 100644
--- a/test/power_divergence.jl
+++ b/test/power_divergence.jl
@@ -198,4 +198,28 @@ MultinomialLRTest(x,y,(1:3,1:3))
 d = [113997 1031298
      334453 37471]
 PowerDivergenceTest(d)
+
+# Pearson's Chi-Squared Test
+# As in https://en.wikipedia.org/wiki/Pearson's_chi-squared_test#Fairness_of_dice
+O = [5,8,9,8,10,20]
+E = fill(10,6)
+m = ChisqTest(O,E)
+
+@test pvalue(m) ≈ 0.01990522033477436
+@test m.stat ≈ 13.4
+@test m.df == 5
+@test m.n == 60
+@test m.residuals ≈ reshape([-1.5811388300841895,-0.6324555320336759,-0.31622776601683794,-0.6324555320336759, 0.0, 3.162277660168379],size(O))
+
+# As in https://en.wikipedia.org/wiki/Pearson's_chi-squared_test#Goodness_of_fit
+O = [44,56]
+E = fill(50,2)
+m = ChisqTest(O,E)
+
+@test pvalue(m) ≈ 0.23013934044341544
+@test m.stat ≈ 1.44
+@test m.df == 1
+@test m.n == 100
+@test m.residuals ≈ reshape([-0.848528137423857,0.848528137423857],size(O))
+
 end