improved output semantic for python objectsยค
when we provide the right semantics to the outputs we increase the tactile representation on assistive techonology. these improvements make it easier for screen reader users to surface lists, tables, and links created from python.
we use the itemscope
and itemtype
properties as the proper semantic attributes to provide type information. these types extend to css selectors that can tailor specific type representations.
itemscope indicates that representation was generated for known type
import nbconvert_a11y.tables
from nbconvert_a11y.outputs import repr_html, repr_semantic
import pandas
%reload_ext nbconvert_a11y.tables
%reload_ext nbconvert_a11y.outputs
comparing the standard dict repr with the semantic repr
data = {'a': 1, 'b': 'abc', 'd': True, 'e': False}
data["f"] = data
print(repr(data))
data
comparing the standard None repr with the semantic repr
print(repr(None))
display(None)
comparing the standard false repr with the semantic repr
print(repr(False))
False
comparing the standard true repr with the semantic repr
print(repr(True))
True
comparing the standard int repr with the semantic repr
print(repr(1000))
1000
comparing the standard float repr with the semantic repr
print(repr(x := 3.14159))
x
comparing the standard list repr with the semantic repr
print(repr(x:= [1,2,3,]))
x
comparing the standard tuple repr with the semantic repr
print(repr(x:= (1,2,3,)))
x
print(repr(x:= {1,2,3,}))
x
comparing the standard dict repr with the semantic repr with recursion
x = dict(a=1, b="abc", c=True)
x.update(z=x)
print(repr(x))
x
import pandas
comparing the standard dataframe repr with the semantic repr
df = pandas.DataFrame(range(x, x+10) for x in range(10))
display({"text/html": df._repr_html_()}, raw=True)
df
comparing the standard ndarray repr with the semantic repr
print(repr(df.values))
df.values
customize table size through pandas options
df = pandas.DataFrame(range(x, x+100) for x in range(200))
with pandas.option_context("display.max_columns", 4, "display.max_rows", 4):
display(df)
custom ndarray size with pandas options
with pandas.option_context("display.max_columns", 4, "display.max_rows", 4):
display(df.values)