We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Example in merge_union_of_records is a no-op
### Which documentation?

Python docstrings

### What needs to be documented?

In the example given, the result type is the same as the input type:

<details>
<summary> Quote from the docstring </summary>

```python
Simplifies unions of records, e.g.

    >>> array = ak.Array([{"a": 1}, {"b": 2}])

into records of options, i.e.

    >>> ak.merge_union_of_records(array)
    <Array [{a: 1, b: None}, {a: None, ...}] type='2 * {a: ?int64, b: ?int64}'>
```

</details>

```python
>>> import awkward as ak
>>> ak.Array([{"a": 1}, {"b": 2}]).type.show()
2 * {
    a: ?int64,
    b: ?int64
}
>>> ak.merge_union_of_records(ak.Array([{"a": 1}, {"b": 2}])).type.show()
2 * {
    a: ?int64,
    b: ?int64
}
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/awkward/operations/ak_merge_union_of_records.py`
Content:
```
1 # BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
2 
3 
4 import awkward as ak
5 from awkward._nplikes.numpylike import NumpyMetadata
6 
7 np = NumpyMetadata.instance()
8 cpu = ak._backends.NumpyBackend.instance()
9 
10 
11 def merge_union_of_records(array, axis=-1, *, highlevel=True, behavior=None):
12     """
13     Args:
14         array: Array-like data (anything #ak.to_layout recognizes).
15         axis (int): The dimension at which this operation is applied.
16             The outermost dimension is `0`, followed by `1`, etc., and negative
17             values count backward from the  innermost: `-1` is the innermost
18             dimension, `-2` is the next level up, etc.
19         highlevel (bool): If True, return an #ak.Array; otherwise, return
20             a low-level #ak.contents.Content subclass.
21         behavior (None or dict): Custom #ak.behavior for the output array, if
22             high-level.
23 
24     Simplifies unions of records, e.g.
25 
26         >>> array = ak.Array([{"a": 1}, {"b": 2}])
27 
28     into records of options, i.e.
29 
30         >>> ak.merge_union_of_records(array)
31         <Array [{a: 1, b: None}, {a: None, ...}] type='2 * {a: ?int64, b: ?int64}'>
32     """
33     with ak._errors.OperationErrorContext(
34         "ak.merge_union_of_records",
35         {"array": array, "axis": axis, "highlevel": highlevel, "behavior": behavior},
36     ):
37         return _impl(array, axis, highlevel, behavior)
38 
39 
40 def _impl(array, axis, highlevel, behavior):
41     behavior = ak._util.behavior_of(array, behavior=behavior)
42     layout = ak.to_layout(array, allow_record=False)
43 
44     def apply_displace_index(layout, backend, **kwargs):
45         if layout.is_record:
46             return layout
47         elif layout.is_option and layout.content.is_record:
48             raise ak._errors.wrap_error(
49                 TypeError(
50                     "optional records cannot be merged by this function. First call `ak.merge_option_of_records` "
51                     "to convert these into records of options."
52                 )
53             )
54         elif layout.is_indexed and layout.content.is_record:
55             record = layout.content
56             # Transpose index-of-record to record-of-index
57             return ak.contents.RecordArray(
58                 [
59                     ak.contents.IndexedArray.simplified(
60                         layout.index, c, parameters=layout._parameters
61                     )
62                     for c in record.contents
63                 ],
64                 record.fields,
65                 record.length,
66                 backend=backend,
67             )
68         else:
69             raise ak._errors.wrap_error(TypeError(layout))
70 
71     def apply(layout, depth, backend, **kwargs):
72         posaxis = ak._util.maybe_posaxis(layout, axis, depth)
73         if depth < posaxis + 1 and layout.is_leaf:
74             raise ak._errors.wrap_error(
75                 np.AxisError(f"axis={axis} exceeds the depth of this array ({depth})")
76             )
77         elif depth == posaxis + 1 and layout.is_union:
78             if all(x.is_record for x in layout.contents):
79                 # First, find all ordered fields, regularising any index-of-record
80                 # such that we have record-of-index
81                 seen_fields = set()
82                 all_fields = []
83                 regularised_contents = []
84                 for content in layout.contents:
85                     # Ensure that we have record-of-index
86                     regularised_content = ak._do.recursively_apply(
87                         content, apply_displace_index
88                     )
89                     regularised_contents.append(regularised_content)
90 
91                     # Find new fields
92                     for field in regularised_content.fields:
93                         if field not in seen_fields:
94                             seen_fields.add(field)
95                             all_fields.append(field)
96 
97                 # Build unions for each field
98                 outer_field_contents = []
99                 for field in all_fields:
100                     field_tags = backend.index_nplike.asarray(layout.tags, copy=True)
101                     field_index = backend.index_nplike.asarray(layout.index, copy=True)
102 
103                     # Build contents for union representing current field
104                     field_contents = [
105                         c.content(field)
106                         for c in regularised_contents
107                         if c.has_field(field)
108                     ]
109 
110                     # Find the best location for option type.
111                     # We will potentially have fewer contents in this per-field union
112                     # than the original outer union-of-records, because some recordarrays
113                     # may not have the given field.
114                     tag_for_missing = 0
115                     for i, content in enumerate(field_contents):
116                         if content.is_option:
117                             tag_for_missing = i
118                             break
119 
120                     # If at least one recordarray doesn't have this field, we add
121                     # a special option
122                     if len(field_contents) < len(regularised_contents):
123                         # Make the tagged content an option, growing by one to ensure we
124                         # have a known `None` value to index into
125                         tagged_content = field_contents[tag_for_missing]
126                         indexedoption_index = backend.index_nplike.arange(
127                             tagged_content.length + 1, dtype=np.int64
128                         )
129                         indexedoption_index[tagged_content.length] = -1
130                         field_contents[
131                             tag_for_missing
132                         ] = ak.contents.IndexedOptionArray.simplified(
133                             ak.index.Index64(indexedoption_index), tagged_content
134                         )
135 
136                     # Now build contents for union, by looping over outermost index
137                     # Overwrite tags to adjust for new contents length
138                     # and use the tagged content for any missing values
139                     k = 0
140                     for j, content in enumerate(regularised_contents):
141                         tag_is_j = field_tags == j
142 
143                         if content.has_field(field):
144                             # Rewrite tags to account for missing fields
145                             field_tags[tag_is_j] = k
146                             k += 1
147 
148                         else:
149                             # Rewrite tags to point to option content
150                             field_tags[tag_is_j] = tag_for_missing
151                             # Point each value to missing value
152                             field_index[tag_is_j] = (
153                                 field_contents[tag_for_missing].length - 1
154                             )
155 
156                     outer_field_contents.append(
157                         ak.contents.UnionArray.simplified(
158                             ak.index.Index8(field_tags),
159                             ak.index.Index64(field_index),
160                             field_contents,
161                         )
162                     )
163                 return ak.contents.RecordArray(
164                     outer_field_contents, all_fields, backend=backend
165                 )
166 
167     out = ak._do.recursively_apply(layout, apply)
168     return ak._util.wrap(out, highlevel=highlevel, behavior=behavior)
169
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/awkward/operations/ak_merge_union_of_records.py b/src/awkward/operations/ak_merge_union_of_records.py
--- a/src/awkward/operations/ak_merge_union_of_records.py
+++ b/src/awkward/operations/ak_merge_union_of_records.py
@@ -23,7 +23,7 @@
 
     Simplifies unions of records, e.g.
 
-        >>> array = ak.Array([{"a": 1}, {"b": 2}])
+        >>> array = ak.concatenate(([{"a": 1}], [{"b": 2}]))
 
     into records of options, i.e.

{"golden_diff": "diff --git a/src/awkward/operations/ak_merge_union_of_records.py b/src/awkward/operations/ak_merge_union_of_records.py\n--- a/src/awkward/operations/ak_merge_union_of_records.py\n+++ b/src/awkward/operations/ak_merge_union_of_records.py\n@@ -23,7 +23,7 @@\n \n     Simplifies unions of records, e.g.\n \n-        >>> array = ak.Array([{\"a\": 1}, {\"b\": 2}])\n+        >>> array = ak.concatenate(([{\"a\": 1}], [{\"b\": 2}]))\n \n     into records of options, i.e.\n", "issue": "Example in merge_union_of_records is a no-op\n### Which documentation?\n\nPython docstrings\n\n### What needs to be documented?\n\nIn the example given, the result type is the same as the input type:\r\n\r\n<details>\r\n<summary> Quote from the docstring </summary>\r\n\r\n```python\r\nSimplifies unions of records, e.g.\r\n\r\n    >>> array = ak.Array([{\"a\": 1}, {\"b\": 2}])\r\n\r\ninto records of options, i.e.\r\n\r\n    >>> ak.merge_union_of_records(array)\r\n    <Array [{a: 1, b: None}, {a: None, ...}] type='2 * {a: ?int64, b: ?int64}'>\r\n```\r\n\r\n</details>\r\n\r\n```python\r\n>>> import awkward as ak\r\n>>> ak.Array([{\"a\": 1}, {\"b\": 2}]).type.show()\r\n2 * {\r\n    a: ?int64,\r\n    b: ?int64\r\n}\r\n>>> ak.merge_union_of_records(ak.Array([{\"a\": 1}, {\"b\": 2}])).type.show()\r\n2 * {\r\n    a: ?int64,\r\n    b: ?int64\r\n}\r\n```\n", "before_files": [{"content": "# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE\n\n\nimport awkward as ak\nfrom awkward._nplikes.numpylike import NumpyMetadata\n\nnp = NumpyMetadata.instance()\ncpu = ak._backends.NumpyBackend.instance()\n\n\ndef merge_union_of_records(array, axis=-1, *, highlevel=True, behavior=None):\n    \"\"\"\n    Args:\n        array: Array-like data (anything #ak.to_layout recognizes).\n        axis (int): The dimension at which this operation is applied.\n            The outermost dimension is `0`, followed by `1`, etc., and negative\n            values count backward from the  innermost: `-1` is the innermost\n            dimension, `-2` is the next level up, etc.\n        highlevel (bool): If True, return an #ak.Array; otherwise, return\n            a low-level #ak.contents.Content subclass.\n        behavior (None or dict): Custom #ak.behavior for the output array, if\n            high-level.\n\n    Simplifies unions of records, e.g.\n\n        >>> array = ak.Array([{\"a\": 1}, {\"b\": 2}])\n\n    into records of options, i.e.\n\n        >>> ak.merge_union_of_records(array)\n        <Array [{a: 1, b: None}, {a: None, ...}] type='2 * {a: ?int64, b: ?int64}'>\n    \"\"\"\n    with ak._errors.OperationErrorContext(\n        \"ak.merge_union_of_records\",\n        {\"array\": array, \"axis\": axis, \"highlevel\": highlevel, \"behavior\": behavior},\n    ):\n        return _impl(array, axis, highlevel, behavior)\n\n\ndef _impl(array, axis, highlevel, behavior):\n    behavior = ak._util.behavior_of(array, behavior=behavior)\n    layout = ak.to_layout(array, allow_record=False)\n\n    def apply_displace_index(layout, backend, **kwargs):\n        if layout.is_record:\n            return layout\n        elif layout.is_option and layout.content.is_record:\n            raise ak._errors.wrap_error(\n                TypeError(\n                    \"optional records cannot be merged by this function. First call `ak.merge_option_of_records` \"\n                    \"to convert these into records of options.\"\n                )\n            )\n        elif layout.is_indexed and layout.content.is_record:\n            record = layout.content\n            # Transpose index-of-record to record-of-index\n            return ak.contents.RecordArray(\n                [\n                    ak.contents.IndexedArray.simplified(\n                        layout.index, c, parameters=layout._parameters\n                    )\n                    for c in record.contents\n                ],\n                record.fields,\n                record.length,\n                backend=backend,\n            )\n        else:\n            raise ak._errors.wrap_error(TypeError(layout))\n\n    def apply(layout, depth, backend, **kwargs):\n        posaxis = ak._util.maybe_posaxis(layout, axis, depth)\n        if depth < posaxis + 1 and layout.is_leaf:\n            raise ak._errors.wrap_error(\n                np.AxisError(f\"axis={axis} exceeds the depth of this array ({depth})\")\n            )\n        elif depth == posaxis + 1 and layout.is_union:\n            if all(x.is_record for x in layout.contents):\n                # First, find all ordered fields, regularising any index-of-record\n                # such that we have record-of-index\n                seen_fields = set()\n                all_fields = []\n                regularised_contents = []\n                for content in layout.contents:\n                    # Ensure that we have record-of-index\n                    regularised_content = ak._do.recursively_apply(\n                        content, apply_displace_index\n                    )\n                    regularised_contents.append(regularised_content)\n\n                    # Find new fields\n                    for field in regularised_content.fields:\n                        if field not in seen_fields:\n                            seen_fields.add(field)\n                            all_fields.append(field)\n\n                # Build unions for each field\n                outer_field_contents = []\n                for field in all_fields:\n                    field_tags = backend.index_nplike.asarray(layout.tags, copy=True)\n                    field_index = backend.index_nplike.asarray(layout.index, copy=True)\n\n                    # Build contents for union representing current field\n                    field_contents = [\n                        c.content(field)\n                        for c in regularised_contents\n                        if c.has_field(field)\n                    ]\n\n                    # Find the best location for option type.\n                    # We will potentially have fewer contents in this per-field union\n                    # than the original outer union-of-records, because some recordarrays\n                    # may not have the given field.\n                    tag_for_missing = 0\n                    for i, content in enumerate(field_contents):\n                        if content.is_option:\n                            tag_for_missing = i\n                            break\n\n                    # If at least one recordarray doesn't have this field, we add\n                    # a special option\n                    if len(field_contents) < len(regularised_contents):\n                        # Make the tagged content an option, growing by one to ensure we\n                        # have a known `None` value to index into\n                        tagged_content = field_contents[tag_for_missing]\n                        indexedoption_index = backend.index_nplike.arange(\n                            tagged_content.length + 1, dtype=np.int64\n                        )\n                        indexedoption_index[tagged_content.length] = -1\n                        field_contents[\n                            tag_for_missing\n                        ] = ak.contents.IndexedOptionArray.simplified(\n                            ak.index.Index64(indexedoption_index), tagged_content\n                        )\n\n                    # Now build contents for union, by looping over outermost index\n                    # Overwrite tags to adjust for new contents length\n                    # and use the tagged content for any missing values\n                    k = 0\n                    for j, content in enumerate(regularised_contents):\n                        tag_is_j = field_tags == j\n\n                        if content.has_field(field):\n                            # Rewrite tags to account for missing fields\n                            field_tags[tag_is_j] = k\n                            k += 1\n\n                        else:\n                            # Rewrite tags to point to option content\n                            field_tags[tag_is_j] = tag_for_missing\n                            # Point each value to missing value\n                            field_index[tag_is_j] = (\n                                field_contents[tag_for_missing].length - 1\n                            )\n\n                    outer_field_contents.append(\n                        ak.contents.UnionArray.simplified(\n                            ak.index.Index8(field_tags),\n                            ak.index.Index64(field_index),\n                            field_contents,\n                        )\n                    )\n                return ak.contents.RecordArray(\n                    outer_field_contents, all_fields, backend=backend\n                )\n\n    out = ak._do.recursively_apply(layout, apply)\n    return ak._util.wrap(out, highlevel=highlevel, behavior=behavior)\n", "path": "src/awkward/operations/ak_merge_union_of_records.py"}], "after_files": [{"content": "# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE\n\n\nimport awkward as ak\nfrom awkward._nplikes.numpylike import NumpyMetadata\n\nnp = NumpyMetadata.instance()\ncpu = ak._backends.NumpyBackend.instance()\n\n\ndef merge_union_of_records(array, axis=-1, *, highlevel=True, behavior=None):\n    \"\"\"\n    Args:\n        array: Array-like data (anything #ak.to_layout recognizes).\n        axis (int): The dimension at which this operation is applied.\n            The outermost dimension is `0`, followed by `1`, etc., and negative\n            values count backward from the  innermost: `-1` is the innermost\n            dimension, `-2` is the next level up, etc.\n        highlevel (bool): If True, return an #ak.Array; otherwise, return\n            a low-level #ak.contents.Content subclass.\n        behavior (None or dict): Custom #ak.behavior for the output array, if\n            high-level.\n\n    Simplifies unions of records, e.g.\n\n        >>> array = ak.concatenate(([{\"a\": 1}], [{\"b\": 2}]))\n\n    into records of options, i.e.\n\n        >>> ak.merge_union_of_records(array)\n        <Array [{a: 1, b: None}, {a: None, ...}] type='2 * {a: ?int64, b: ?int64}'>\n    \"\"\"\n    with ak._errors.OperationErrorContext(\n        \"ak.merge_union_of_records\",\n        {\"array\": array, \"axis\": axis, \"highlevel\": highlevel, \"behavior\": behavior},\n    ):\n        return _impl(array, axis, highlevel, behavior)\n\n\ndef _impl(array, axis, highlevel, behavior):\n    behavior = ak._util.behavior_of(array, behavior=behavior)\n    layout = ak.to_layout(array, allow_record=False)\n\n    def apply_displace_index(layout, backend, **kwargs):\n        if layout.is_record:\n            return layout\n        elif layout.is_option and layout.content.is_record:\n            raise ak._errors.wrap_error(\n                TypeError(\n                    \"optional records cannot be merged by this function. First call `ak.merge_option_of_records` \"\n                    \"to convert these into records of options.\"\n                )\n            )\n        elif layout.is_indexed and layout.content.is_record:\n            record = layout.content\n            # Transpose index-of-record to record-of-index\n            return ak.contents.RecordArray(\n                [\n                    ak.contents.IndexedArray.simplified(\n                        layout.index, c, parameters=layout._parameters\n                    )\n                    for c in record.contents\n                ],\n                record.fields,\n                record.length,\n                backend=backend,\n            )\n        else:\n            raise ak._errors.wrap_error(TypeError(layout))\n\n    def apply(layout, depth, backend, **kwargs):\n        posaxis = ak._util.maybe_posaxis(layout, axis, depth)\n        if depth < posaxis + 1 and layout.is_leaf:\n            raise ak._errors.wrap_error(\n                np.AxisError(f\"axis={axis} exceeds the depth of this array ({depth})\")\n            )\n        elif depth == posaxis + 1 and layout.is_union:\n            if all(x.is_record for x in layout.contents):\n                # First, find all ordered fields, regularising any index-of-record\n                # such that we have record-of-index\n                seen_fields = set()\n                all_fields = []\n                regularised_contents = []\n                for content in layout.contents:\n                    # Ensure that we have record-of-index\n                    regularised_content = ak._do.recursively_apply(\n                        content, apply_displace_index\n                    )\n                    regularised_contents.append(regularised_content)\n\n                    # Find new fields\n                    for field in regularised_content.fields:\n                        if field not in seen_fields:\n                            seen_fields.add(field)\n                            all_fields.append(field)\n\n                # Build unions for each field\n                outer_field_contents = []\n                for field in all_fields:\n                    field_tags = backend.index_nplike.asarray(layout.tags, copy=True)\n                    field_index = backend.index_nplike.asarray(layout.index, copy=True)\n\n                    # Build contents for union representing current field\n                    field_contents = [\n                        c.content(field)\n                        for c in regularised_contents\n                        if c.has_field(field)\n                    ]\n\n                    # Find the best location for option type.\n                    # We will potentially have fewer contents in this per-field union\n                    # than the original outer union-of-records, because some recordarrays\n                    # may not have the given field.\n                    tag_for_missing = 0\n                    for i, content in enumerate(field_contents):\n                        if content.is_option:\n                            tag_for_missing = i\n                            break\n\n                    # If at least one recordarray doesn't have this field, we add\n                    # a special option\n                    if len(field_contents) < len(regularised_contents):\n                        # Make the tagged content an option, growing by one to ensure we\n                        # have a known `None` value to index into\n                        tagged_content = field_contents[tag_for_missing]\n                        indexedoption_index = backend.index_nplike.arange(\n                            tagged_content.length + 1, dtype=np.int64\n                        )\n                        indexedoption_index[tagged_content.length] = -1\n                        field_contents[\n                            tag_for_missing\n                        ] = ak.contents.IndexedOptionArray.simplified(\n                            ak.index.Index64(indexedoption_index), tagged_content\n                        )\n\n                    # Now build contents for union, by looping over outermost index\n                    # Overwrite tags to adjust for new contents length\n                    # and use the tagged content for any missing values\n                    k = 0\n                    for j, content in enumerate(regularised_contents):\n                        tag_is_j = field_tags == j\n\n                        if content.has_field(field):\n                            # Rewrite tags to account for missing fields\n                            field_tags[tag_is_j] = k\n                            k += 1\n\n                        else:\n                            # Rewrite tags to point to option content\n                            field_tags[tag_is_j] = tag_for_missing\n                            # Point each value to missing value\n                            field_index[tag_is_j] = (\n                                field_contents[tag_for_missing].length - 1\n                            )\n\n                    outer_field_contents.append(\n                        ak.contents.UnionArray.simplified(\n                            ak.index.Index8(field_tags),\n                            ak.index.Index64(field_index),\n                            field_contents,\n                        )\n                    )\n                return ak.contents.RecordArray(\n                    outer_field_contents, all_fields, backend=backend\n                )\n\n    out = ak._do.recursively_apply(layout, apply)\n    return ak._util.wrap(out, highlevel=highlevel, behavior=behavior)\n", "path": "src/awkward/operations/ak_merge_union_of_records.py"}]}