Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Greek small letter mu #14426

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions IPython/core/magics/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,17 +1592,17 @@ def _format_time(timespan, precision=3):
break
return " ".join(time)

# Unfortunately the unicode 'micro' symbol can cause problems in
# certain terminals.

# Unfortunately characters outside of range(128) can cause problems in
# certain terminals.
# See bug: https://bugs.launchpad.net/ipython/+bug/348466
# Try to prevent crashes by being more secure than it needs to
# E.g. eclipse is able to print a µ, but has no sys.stdout.encoding set.
units = [u"s", u"ms",u'us',"ns"] # the save value
if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding:
units = ["s", "ms", "us", "ns"] # the safe value
if hasattr(sys.stdout, "encoding") and sys.stdout.encoding:
try:
u'\xb5'.encode(sys.stdout.encoding)
units = [u"s", u"ms",u'\xb5s',"ns"]
"μ".encode(sys.stdout.encoding)
units = ["s", "ms", "μs", "ns"]
except:
pass
scaling = [1, 1e3, 1e6, 1e9]
Expand Down
8 changes: 8 additions & 0 deletions IPython/core/tests/test_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,14 @@ def test_time_local_ns():
del ip.user_ns["myvar"]


def test_time_microseconds_display():
"""Ensure ASCII is used when necessary"""
with mock.patch("sys.stdout", io.TextIOWrapper(StringIO(), encoding="utf-8")):
assert execution._format_time(0.000001) == "1 \u03bcs"
with mock.patch("sys.stdout", io.TextIOWrapper(StringIO(), encoding="ascii")):
assert execution._format_time(0.000001) == "1 us"


# Test %%capture magic. Added to test issue #13926
def test_capture():
ip = get_ipython()
Expand Down
Loading