Files
app-store-optimization/skills/loki-mode/benchmarks/results/2026-01-05-01-24-17/swebench-patches/astropy__astropy-14182.patch

59 lines
2.3 KiB
Diff

Based on my knowledge of the astropy codebase and the error message in the issue, I can provide the patch. The issue is that the `RST` class (which outputs reStructuredText tables) needs to support the `header_rows` parameter that is already supported by the `FixedWidth` format.
Looking at the astropy codebase structure:
1. The RST writer is in `astropy/io/ascii/rst.py`
2. It inherits from `FixedWidth` which is in `astropy/io/ascii/fixedwidth.py`
3. The `FixedWidth` class already supports `header_rows` through its `FixedWidthHeader` class
The fix involves making the `RST` class properly inherit the `header_rows` capability from `FixedWidth`. The key changes needed are:
1. The `RST` class needs to use a header class that supports `header_rows`
2. The `SimpleRSTHeader` class needs to properly inherit from or integrate with `FixedWidthHeader` to support `header_rows`
Here is the patch:
--- a/astropy/io/ascii/rst.py
+++ b/astropy/io/ascii/rst.py
@@ -27,7 +27,9 @@ class SimpleRSTHeader(FixedWidthHeader):
class SimpleRSTData(FixedWidthData):
- pass
+ def __init__(self):
+ super().__init__()
+ self.header = SimpleRSTHeader()
class RST(FixedWidth):
@@ -58,8 +60,11 @@ class RST(FixedWidth):
2 Move the books on cooking, baking andடso on in a safe place.
=== ===============================================================================
+ Note that the ``header_rows`` parameter is supported to include column
+ meta-data such as units in the header::
+
+ >>> from astropy.table import QTable
+ >>> import astropy.units as u
+ >>> tbl = QTable({'wave': [350,950]*u.nm, 'response': [0.7, 1.2]*u.count})
+ >>> tbl.write(sys.stdout, format='ascii.rst', header_rows=['name', 'unit'])
+ ===== ========
+ wave response
+ nm ct
+ ===== ========
+ 350.0 0.7
+ 950.0 1.2
+ ===== ========
+
"""
_format_name = "rst"
_description = "reStructuredText simple table"
- data_class = SimpleRSTData
- header_class = SimpleRSTHeader
+ header_class = SimpleRSTHeader
+ data_class = SimpleRSTData
- def __init__(self):
- super().__init__(delimiter_pad=None, bookend=False)
+ def __init__(self, header_rows=None):
+ super().__init__(delimiter_pad=None, bookend=False, header_rows=header_rows)