← mined_oracle

rich_3332

failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(None) · None tool calls · 0 s · Textualize/rich

Task input

(not found in data/tasks.jsonl)

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Patch

--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Fixed issue with Segment._split_cells https://github.com/Textualize/rich/pull/3506
 
+### Added
+
+- Add a new `column` object `IterationSpeedColumn`. https://github.com/Textualize/rich/pull/3332
+
 ## [13.8.1] - 2024-09-10
 
 ### Fixed
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -86,4 +86,5 @@ The following people have contributed to the development of Rich:
 - [Pierro](https://github.com/xpierroz)
 - [Bernhard Wagner](https://github.com/bwagner)
 - [Aaron Beaudoin](https://github.com/AaronBeaudoin)
+- [chthollyphile](https://github.com/chthollyphile)
 - [Jonathan Helmus](https://github.com/jjhelmus)
--- a/docs/source/progress.rst
+++ b/docs/source/progress.rst
@@ -163,6 +163,7 @@ The following column objects are available:
 - :class:`~rich.progress.TransferSpeedColumn` Displays transfer speed (assumes the steps are bytes).
 - :class:`~rich.progress.SpinnerColumn` Displays a "spinner" animation.
 - :class:`~rich.progress.RenderableColumn` Displays an arbitrary Rich renderable in the column.
+- :class:`~rich.progress.IterationSpeedColumn` Displays iteration speed in it/s (iterations per second).
 
 To implement your own columns, extend the :class:`~rich.progress.ProgressColumn` class and use it as you would the other columns.
 
--- a/rich/progress.py
+++ b/rich/progress.py
@@ -922,6 +922,25 @@ class TransferSpeedColumn(ProgressColumn):
         return Text(f"{data_speed}/s", style="progress.data.speed")
 
 
+class IterationSpeedColumn(ProgressColumn):
+    """Renders iterations per second, e.g. '11.4 it/s'."""
+    
+    def render(self, task: "Task") -> Text:
+        last_speed = task.last_speed if hasattr(task, 'last_speed') else None
+        if task.finished and last_speed is not None:
+            return Text(f"{last_speed} it/s", style="progress.data.speed")   
+        if task.speed is None:
+            return Text("", style="progress.data.speed")
+        unit, suffix = filesize.pick_unit_and_suffix(
+            int(task.speed),
+            ["", "×10³", "×10⁶", "×10⁹", "×10¹²"],
+            1000,
+        )
+        data_speed = task.speed / unit
+        task.last_speed = f"{data_speed:.1f}{suffix}"
+        return Text(f"{task.last_speed} it/s", style="progress.data.speed")
+
+
 class ProgressSample(NamedTuple):
     """Sample of progress for a given time."""
 

Test output

show
 \x1b[0m \x1b[32m12/10  \x1b[0m \x1b[31m1     \x1b[0m \x1b[32m12/10\x1b[0m \x1b[32m12 of  \x1b[0m \x1b[31m1.3    \x1b[0m\n                              \x1b[32mbytes \x1b[0m \x1b[32mbytes \x1b[0m \x1b[32mbytes  \x1b[0m \x1b[31mbyte/s\x1b[0m       \x1b[32m10     \x1b[0m \x1b[31mit/s   \x1b[0m\ntest bar \x1b[38;2;114;156;31m━━━━━━\x1b[0m \x1b[36m0:00:…\x1b[0m \x1b[33m0:00:…\x1b[0m \x1b[32m16    \x1b[0m \x1b[32m7     \x1b[0m \x1b[32m16/7   \x1b[0m \x1b[31m2     \x1b[0m \x1b[32m16/7 \x1b[0m \x1b[32m16 of 7\x1b[0m \x1b[31m1.5    \x1b[0m\n                              \x1b[32mbytes \x1b[0m \x1b[32mbytes \x1b[0m \x1b[32mbytes  \x1b[0m \x1b[31mbytes…\x1b[0m               \x1b[31mit/s   \x1b[0m\n\x1b[?25h\r\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K"
    
>       assert result == expected
E       AssertionError: assert '\x1b[?25ltes...x1b[1A\x1b[2K' == '\x1b[?25ltes...x1b[1A\x1b[2K'
E         
E         Skipping 137 identical leading characters in diff, use -v to show
E         + m  0/10  0 of 10 
E         +                                                     bytes                      
E         + test bar ━━━━━━━━━ -:--:-- 0:00:19 0 bytes 7 bytes  0/7 bytes ? 0/7   0 of 7   
E         + foo
E         - m  0/m0:00:07 0 bytes 10 bytes 0/10      ?  0/10  0 of 10 ...
E         
E         ...Full output truncated (23 lines hidden), use '-vv' to show

tests/test_progress.py:384: AssertionError
----------------------------- Captured stdout call -----------------------------
'\x1b[?25ltest foo \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:07\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m10 bytes\x1b[0m \x1b[32m0/10     \x1b[0m \x1b[31m?\x1b[0m \x1b[32m 0/10\x1b[0m \x1b[32m 0 of 10\x1b[0m \n                                                    \x1b[32mbytes    \x1b[0m                  \ntest bar \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:19\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m7 bytes \x1b[0m \x1b[32m0/7 bytes\x1b[0m \x1b[31m?\x1b[0m \x1b[32m0/7  \x1b[0m \x1b[32m0 of 7  \x1b[0m \r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2Kfoo\ntest foo \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:07\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m10 bytes\x1b[0m \x1b[32m0/10     \x1b[0m \x1b[31m?\x1b[0m \x1b[32m 0/10\x1b[0m \x1b[32m 0 of 10\x1b[0m \n                                                    \x1b[32mbytes    \x1b[0m                  \ntest bar \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:19\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m7 bytes \x1b[0m \x1b[32m0/7 bytes\x1b[0m \x1b[31m?\x1b[0m \x1b[32m0/7  \x1b[0m \x1b[32m0 of 7  \x1b[0m \r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[2;36m[TIME]\x1b[0m\x1b[2;36m \x1b[0mhello                                                                    \ntest foo \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:07\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m10 bytes\x1b[0m \x1b[32m0/10     \x1b[0m \x1b[31m?\x1b[0m \x1b[32m 0/10\x1b[0m \x1b[32m 0 of 10\x1b[0m \n                                                    \x1b[32mbytes    \x1b[0m                  \ntest bar \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:19\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m7 bytes \x1b[0m \x1b[32m0/7 bytes\x1b[0m \x1b[31m?\x1b[0m \x1b[32m0/7  \x1b[0m \x1b[32m0 of 7  \x1b[0m \r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2Kworld\ntest foo \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:07\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m10 bytes\x1b[0m \x1b[32m0/10     \x1b[0m \x1b[31m?\x1b[0m \x1b[32m 0/10\x1b[0m \x1b[32m 0 of 10\x1b[0m \n                                                    \x1b[32mbytes    \x1b[0m                  \ntest bar \x1b[38;5;237m━━━━━━━━━\x1b[0m \x1b[36m-:--:--\x1b[0m \x1b[33m0:00:19\x1b[0m \x1b[32m0 bytes\x1b[0m \x1b[32m7 bytes \x1b[0m \x1b[32m0/7 bytes\x1b[0m \x1b[31m?\x1b[0m \x1b[32m0/7  \x1b[0m \x1b[32m0 of 7  \x1b[0m \r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2Ktest foo \x1b[38;2;114;156;31m━━━━━━\x1b[0m \x1b[36m0:00:…\x1b[0m \x1b[33m0:00:…\x1b[0m \x1b[32m12    \x1b[0m \x1b[32m10    \x1b[0m \x1b[32m12/10  \x1b[0m \x1b[31m1     \x1b[0m \x1b[32m12/10\x1b[0m \x1b[32m12 of  \x1b[0m \x1b[31m1.3    \x1b[0m\n                              \x1b[32mbytes \x1b[0m \x1b[32mbytes \x1b[0m \x1b[32mbytes  \x1b[0m \x1b[31mbyte/s\x1b[0m       \x1b[32m10     \x1b[0m \x1b[31mit/s   \x1b[0m\ntest bar \x1b[38;2;114;156;31m━━━━━━\x1b[0m \x1b[36m0:00:…\x1b[0m \x1b[33m0:00:…\x1b[0m \x1b[32m16    \x1b[0m \x1b[32m7     \x1b[0m \x1b[32m16/7   \x1b[0m \x1b[31m2     \x1b[0m \x1b[32m16/7 \x1b[0m \x1b[32m16 of 7\x1b[0m \x1b[31m1.5    \x1b[0m\n                              \x1b[32mbytes \x1b[0m \x1b[32mbytes \x1b[0m \x1b[32mbytes  \x1b[0m \x1b[31mbytes…\x1b[0m               \x1b[31mit/s   \x1b[0m\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2Ktest foo \x1b[38;2;114;156;31m━━━━━━\x1b[0m \x1b[36m0:00:…\x1b[0m \x1b[33m0:00:…\x1b[0m \x1b[32m12    \x1b[0m \x1b[32m10    \x1b[0m \x1b[32m12/10  \x1b[0m \x1b[31m1     \x1b[0m \x1b[32m12/10\x1b[0m \x1b[32m12 of  \x1b[0m \x1b[31m1.3    \x1b[0m\n                              \x1b[32mbytes \x1b[0m \x1b[32mbytes \x1b[0m \x1b[32mbytes  \x1b[0m \x1b[31mbyte/s\x1b[0m       \x1b[32m10     \x1b[0m \x1b[31mit/s   \x1b[0m\ntest bar \x1b[38;2;114;156;31m━━━━━━\x1b[0m \x1b[36m0:00:…\x1b[0m \x1b[33m0:00:…\x1b[0m \x1b[32m16    \x1b[0m \x1b[32m7     \x1b[0m \x1b[32m16/7   \x1b[0m \x1b[31m2     \x1b[0m \x1b[32m16/7 \x1b[0m \x1b[32m16 of 7\x1b[0m \x1b[31m1.5    \x1b[0m\n                              \x1b[32mbytes \x1b[0m \x1b[32mbytes \x1b[0m \x1b[32mbytes  \x1b[0m \x1b[31mbytes…\x1b[0m               \x1b[31mit/s   \x1b[0m\n\x1b[?25h\r\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K'
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 21 passed in 0.17s