nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sciunto-org/python-bibtexparser
Pull request #77 (2015-09-02 17:05:26)

place comma after indent for comma_first=True in bwriter
changes:
```
@book{Bird1987
,   author = {Bird, R.B. and Armstrong, R.C. and Hassager, O.}
,   edition = {2}
,   publisher = {Wiley Edition}
,   title = {Dynamics of Polymeric Liquid}
,   volume = {1}
,   year = {1987}
}
```

to:
```
@book{Bird1987
   , author = {Bird, R.B. and Armstrong, R.C. and Hassager, O.}
   , edition = {2}
   , publisher = {Wiley Edition}
   , title = {Dynamics of Polymeric Liquid}
   , volume = {1}
   , year = {1987}
}
```

which preserves visual indentation.

edit: placed examples within code blocks


Patch:
diff --git a/bibtexparser/bwriter.py b/bibtexparser/bwriter.py
index a183e39..54c7882 100644
--- a/bibtexparser/bwriter.py
+++ b/bibtexparser/bwriter.py
@@ -92,7 +92,7 @@ class BibTexWriter(object):
         for field in [i for i in sorted(entry) if i not in ['ENTRYTYPE', 'ID']]:
             try:
                 if self.comma_first:
-                    bibtex += "\n," + self.indent + field + " = {" + entry[field] + "}"
+                    bibtex += "\n" + self.indent + ", " + field + " = {" + entry[field] + "}"
                 else:
                     bibtex += ",\n" + self.indent + field + " = {" + entry[field] + "}"
             except TypeError:


Test patch:
diff --git a/bibtexparser/tests/data/article_comma_first.bib b/bibtexparser/tests/data/article_comma_first.bib
index 0be3e73..83882f4 100644
--- a/bibtexparser/tests/data/article_comma_first.bib
+++ b/bibtexparser/tests/data/article_comma_first.bib
@@ -1,11 +1,11 @@
 @ARTICLE{Cesar2013
-, author = {Jean Cesar}
-, title = {An amazing title}
-, year = {2013}
-, volume = {12}
-, journal = {Nice Journal}
-, comments = {A comment}
-, keyword = {keyword1, keyword2}
+ , author = {Jean Cesar}
+ , title = {An amazing title}
+ , year = {2013}
+ , volume = {12}
+ , journal = {Nice Journal}
+ , comments = {A comment}
+ , keyword = {keyword1, keyword2}
 }
 
 @ARTICLE{ Baltazar2013
diff --git a/bibtexparser/tests/data/book_comma_first.bib b/bibtexparser/tests/data/book_comma_first.bib
index f2ab70e..5691da9 100644
--- a/bibtexparser/tests/data/book_comma_first.bib
+++ b/bibtexparser/tests/data/book_comma_first.bib
@@ -1,9 +1,9 @@
 @book{Bird1987
-,   author = {Bird, R.B. and Armstrong, R.C. and Hassager, O.}
-,   edition = {2}
-,   publisher = {Wiley Edition}
-,   title = {Dynamics of Polymeric Liquid}
-,   volume = {1}
-,   year = {1987}
+   , author = {Bird, R.B. and Armstrong, R.C. and Hassager, O.}
+   , edition = {2}
+   , publisher = {Wiley Edition}
+   , title = {Dynamics of Polymeric Liquid}
+   , volume = {1}
+   , year = {1987}
 }
Repository: sciunto-org/python-bibtexparser
Pull request #182 (2017-09-26 23:15:24)

Strip the latex command str for latex_to_unicode()
In order to fix some commands like "\texttimes", for the cases if they
are written as "\ŧexttimes{}" or "{\texttimes}", the value to lookup has
to stripped.


Patch:
diff --git a/bibtexparser/latexenc.py b/bibtexparser/latexenc.py
index 2a30f62..e192fc4 100644
--- a/bibtexparser/latexenc.py
+++ b/bibtexparser/latexenc.py
@@ -52,7 +52,7 @@ def _replace_latex(string, latex, unicod):
 
 def _replace_all_latex(string, replacements):
     for u, l in replacements:
-        string = _replace_latex(string, l, u)
+        string = _replace_latex(string, l.rstrip(), u)
     return string
 
 


Test patch:
diff --git a/bibtexparser/tests/test_customization.py b/bibtexparser/tests/test_customization.py
index d6d42b5..2d97538 100644
--- a/bibtexparser/tests/test_customization.py
+++ b/bibtexparser/tests/test_customization.py
@@ -100,6 +100,10 @@ class TestBibtexParserMethod(unittest.TestCase):
         result = convert_to_unicode(record)
         expected = {'title': "île"}
         self.assertEqual(result, expected)
+        record = {'title': r"\texttimes{}{\texttimes}\texttimes"}
+        result = convert_to_unicode(record)
+        expected = {'title': "×××"}
+        self.assertEqual(result, expected)
 
     ###########
     # homogenize
Repository: sciunto-org/python-bibtexparser
Pull request #423 (2023-11-23 23:07:30)

:bug: Fix bug in `von`-part name parsing
The current system has a name parsing issue around capitalization in comma-style names. This means that

```
aa bb, CC
```

gets parsed as

```
last: aa bb
first: CC
von: <empty>
```

but BibTeX parses this as

```
last: bb
first: CC
von: aa
```

I have modified the parsing code and added relevant test cases drawn from the Tame The BeaST BibTeX reference document.

Style-wise, I found the list manipulation difficult to follow; I added a helper function `rindex`, which makes it easier to understand IMO. This should probably go in a utility file or something, but I didn't see one in the project.

I believe these changes will fix at least some of the failing test cases in the name merging PR here: #422 


Patch:
diff --git a/bibtexparser/middlewares/names.py b/bibtexparser/middlewares/names.py
index 8898eae..9b6d308 100644
--- a/bibtexparser/middlewares/names.py
+++ b/bibtexparser/middlewares/names.py
@@ -424,11 +424,17 @@ def parse_single_name_into_parts(name, strict=True):
         else:
             lcases = cases[0]
 
-            #
+            def rindex(l, x, default):
+                """Returns the index of the rightmost occurence of x in l."""
+                for i in range(len(l) - 1, -1, -1):
+                    if l[i] == x:
+                        return i
+                return default
+
+            # Check if at least one of the words is lowercase
             if 0 in lcases:
-                split = len(lcases) - lcases[::-1].index(0)
-                if split == len(lcases):
-                    split = 0  # Last cannot be empty.
+                # Excluding the last word, find the index of the last lower word
+                split = rindex(lcases[:-1], 0, -1) + 1
                 parts.von = sections[0][:split]
                 parts.last = sections[0][split:]
 


Test patch:
diff --git a/tests/middleware_tests/test_names.py b/tests/middleware_tests/test_names.py
index 4a420a3..fb5e6bc 100644
--- a/tests/middleware_tests/test_names.py
+++ b/tests/middleware_tests/test_names.py
@@ -825,6 +825,27 @@ REGULAR_NAME_PARTS_PARSING_TEST_CASES = (
         r"Brand\~{a}o, F",
         {"first": ["F"], "von": [], "last": ["Brand\\", "{a}o"], "jr": []},
     ),
+    ###############################################################################
+    #
+    # Group 2 examples from Tame the BeaST
+    #
+    ###############################################################################
+    (
+        r"de la fontaine, Jean",
+        {"first": ["Jean"], "von": ["de", "la"], "last": ["fontaine"], "jr": []},
+    ),
+    (
+        r"De La Fontaine, Jean",
+        {"first": ["Jean"], "von": [], "last": ["De", "La", "Fontaine"], "jr": []},
+    ),
+    (
+        r"De la Fontaine, Jean",
+        {"first": ["Jean"], "von": ["De", "la"], "last": ["Fontaine"], "jr": []},
+    ),
+    (
+        r"de La Fontaine, Jean",
+        {"first": ["Jean"], "von": ["de"], "last": ["La", "Fontaine"], "jr": []},
+    ),
 )
Repository: sciunto-org/python-bibtexparser
Pull request #466 (2024-02-08 10:05:59)

Rename `pop_field` -> `pop` (with default) to make API closer to `dict`
Fixes https://github.com/sciunto-org/python-bibtexparser/issues/461


Patch:
diff --git a/README.md b/README.md
index f4e85e3..2781ae6 100644
--- a/README.md
+++ b/README.md
@@ -90,7 +90,7 @@ Writes the content of a bibtex library to a `.bib` file. Optional formatting par
 
 ## About
 
-Since 2022, `bibtexparser` is primarily written and maintained by Michael Weiss ([@MiWeiss](https://github.com/MiWeiss/)). 
+Since 2022, `bibtexparser` is primarily written and maintained by Michael Weiss ([@MiWeiss](https://github.com/MiWeiss/)). In 2024, Tom de Geus ([@tdegeus](https://github.com/tdegeus)) joined as co-maintainer. 
 
 Credits and thanks to the many contributors who helped creating this library, including
 François Boulogne ([@sciunto](https://github.com/sciunto/), creator of the first version) and Olivier Mangin ([@omangin](https://github.com/omangin/), long-term contributor).
diff --git a/bibtexparser/model.py b/bibtexparser/model.py
index b6b38be..cb19a59 100644
--- a/bibtexparser/model.py
+++ b/bibtexparser/model.py
@@ -305,12 +305,15 @@ class Entry(Block):
         else:
             self._fields.append(field)
 
-    def pop_field(self, key: str) -> Optional[Field]:
-        """Removes and returns the field with the given key, if present."""
+    def pop(self, key: str, default=None) -> Optional[Field]:
+        """Removes and returns the field with the given key.
+
+        :param key: The key of the field to remove.
+        :param default: The value to return if the field does not exist."""
         try:
             field = self.fields_dict.pop(key)
         except KeyError:
-            return None
+            return default
 
         self._fields = [f for f in self._fields if f.key != key]
         return field
@@ -345,9 +348,9 @@ class Entry(Block):
         """Dict-mimicking index.
 
         This serves for partial v1.x backwards compatibility,
-        as well as for a shorthand for `pop_field`.
+        as well as for a shorthand for `pop`.
         """
-        self.pop_field(key)
+        self.pop(key)
 
     def items(self):
         """Dict-mimicking, for partial v1.x backwards compatibility.


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
index 3f98771..d39e0c3 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -77,7 +77,17 @@ def test_entry_deepcopy():
     assert entry_1.fields_dict["field"] == entry_2.fields_dict["field"]
 
 
-def test_entry_contain():
+def test_entry_pop():
+    entry1 = Entry(
+        "article", "key", [Field("field", "value", 1), Field("foo", "bar", 2)], 1, "raw"
+    )
+    entry2 = Entry("article", "key", [Field("field", "value", 1)], 1, "raw")
+    assert entry1.pop("other", "default") == "default"
+    assert entry1.pop("foo") == Field("foo", "bar", 2)
+    assert entry1 == entry2
+
+
+def test_entry_contains():
     entry = Entry("article", "key", [Field("field", "value", 1)], 1, "raw")
     assert "field" in entry
     assert "other" not in entry
Repository: sciunto-org/python-bibtexparser
Pull request #468 (2024-02-14 08:06:28)

:sparkles: Add `get` to mimic `dict`


Patch:
diff --git a/bibtexparser/model.py b/bibtexparser/model.py
index cb19a59..71283dd 100644
--- a/bibtexparser/model.py
+++ b/bibtexparser/model.py
@@ -318,6 +318,13 @@ class Entry(Block):
         self._fields = [f for f in self._fields if f.key != key]
         return field
 
+    def get(self, key: str, default=None) -> Optional[Field]:
+        """Returns the field with the given key, or the default value if it does not exist.
+
+        :param key: The key of the field.
+        :param default: The value to return if the field does not exist."""
+        return self.fields_dict.get(key, default)
+
     def __contains__(self, key: str) -> bool:
         """Dict-mimicking ``in`` operator."""
         return key in self.fields_dict


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
index d39e0c3..198e8a0 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -77,6 +77,18 @@ def test_entry_deepcopy():
     assert entry_1.fields_dict["field"] == entry_2.fields_dict["field"]
 
 
+def test_entry_get():
+    entry1 = Entry(
+        "article", "key", [Field("field", "value", 1), Field("foo", "bar", 2)], 1, "raw"
+    )
+    entry2 = Entry(
+        "article", "key", [Field("field", "value", 1), Field("foo", "bar", 2)], 1, "raw"
+    )
+    assert entry1.get("other", "default") == "default"
+    assert entry1.get("foo") == Field("foo", "bar", 2)
+    assert entry1 == entry2
+
+
 def test_entry_pop():
     entry1 = Entry(
         "article", "key", [Field("field", "value", 1), Field("foo", "bar", 2)], 1, "raw"
Repository: sciunto-org/python-bibtexparser
Pull request #476 (2024-03-14 08:44:43)

:bug: fix `split_multiple_persons_names` with single-char middlenames
Fixes https://github.com/sciunto-org/python-bibtexparser/issues/475


Patch:
diff --git a/bibtexparser/middlewares/names.py b/bibtexparser/middlewares/names.py
index d067222..415beea 100644
--- a/bibtexparser/middlewares/names.py
+++ b/bibtexparser/middlewares/names.py
@@ -600,8 +600,8 @@ def split_multiple_persons_names(names):
                 step = FIND_A
                 possible_end = pos - 1
 
-        # Looking for the letter a. NB., we can have multiple whitespace
-        # characters so we need to handle that here.
+        # Looking for the letter "a".
+        # NB, we can have multiple whitespace characters so we need to handle that here.
         elif step == FIND_A:
             if char in ("a", "A"):
                 step = FIND_N
@@ -612,6 +612,9 @@ def split_multiple_persons_names(names):
         elif step == FIND_N:
             if char in ("n", "N"):
                 step = FIND_D
+            elif char in whitespace:
+                step = FIND_A
+                possible_end = pos - 1
             else:
                 step = START_WHITESPACE
 
@@ -619,6 +622,9 @@ def split_multiple_persons_names(names):
         elif step == FIND_D:
             if char in ("d", "D"):
                 step = END_WHITESPACE
+            elif char in whitespace:
+                step = FIND_A
+                possible_end = pos - 1
             else:
                 step = START_WHITESPACE
 


Test patch:
diff --git a/tests/middleware_tests/test_names.py b/tests/middleware_tests/test_names.py
index 5da4d81..fc99d50 100644
--- a/tests/middleware_tests/test_names.py
+++ b/tests/middleware_tests/test_names.py
@@ -75,6 +75,8 @@ from tests.middleware_tests.middleware_test_util import assert_nonfield_entry_at
         ("Harry Fellowes~and D. Drumpf", ["Harry Fellowes~and D. Drumpf"]),
         ("Harry Fellowes~and~D. Drumpf", ["Harry Fellowes~and~D. Drumpf"]),
         ("Harry Fellowes and~D. Drumpf", ["Harry Fellowes and~D. Drumpf"]),
+        ("Doe, John A and Doe, Jane", ["Doe, John A", "Doe, Jane"]),
+        ("Doe, John AN and Doe, Jane", ["Doe, John AN", "Doe, Jane"]),
         ("      ", []),
         ("\t\n \t", []),
         ("~", ["~"]),