"", 100), (None, None))
test_eq(in_range("in 10", 100), (0, 10))
test_eq(in_range("in 1/10", 100), (0, 10))
test_eq(in_range("in F/10", 100), (0, 10))
test_eq(in_range("in 3/10", 100), (2, 10))
test_eq(in_range(=("in 10", 5))
test_fail(in_range, args=("in 10/1", 100)) test_fail(in_range, args
browse
Helpers for browse, head, and tail magics
Parsing Stata code for browse magic
in_range
in_range (stata_in_code, count)
Return in-statement range
Negative indices are converted to positive, following Stata syntax:
"in -10/-1", 41), (31, 41)) test_eq(in_range(
Head/tail/browse magic helpers
parse_browse_magic
parse_browse_magic (code)
= "le if year==1920 in 1/10, noformat"
code
test_eq(parse_browse_magic(code), None, ['le'], 'if year==1920', 'in 1/10', '', 'noformat')
( )
"gen date = dofy(year)")
run_single("10 le* if date==mdy(1, 1, 1910), noformat"),
test_eq(parse_browse_magic(10, ['le'], 'if date==mdy(1, 1, 1910)', '', '', 'noformat')
(
)"drop date") run_single(
get_df
get_df (obs_range, var, stata_if_code, missingval, valuelabel, sformat)
Head/tail magic helpers
headtail_df_params
headtail_df_params (code, count, missing_config, tail=False)
"", 50, "."),
test_eq(headtail_df_params(range(0, 5), None, '', ".", True, True))) ((
"10 y le*, noformat", 50, "."),
test_eq(headtail_df_params(range(0, 10), ['year', 'le'], '', ".", True, False))) ((
"10 y le*, noformat", 50, ".", tail=True),
test_eq(headtail_df_params(range(40, 50), ['year', 'le'], '', ".", True, False))) ((
headtail_get_df
headtail_get_df (obs_range, var, stata_if_code, missingval, valuelabel, sformat)
*headtail_df_params('if year<1903', obs_count(), ".")) headtail_get_df(
year | le | |
---|---|---|
1 | 1900 | 47.3 |
2 | 1901 | . |
3 | 1902 | 51.5 |
*headtail_df_params('if year<1903', obs_count(), ".")),
test_eq(headtail_get_df(*headtail_df_params('if year<1903', obs_count(), ".", tail=True)),) headtail_get_df(
*headtail_df_params('if year>1910', obs_count(), ".")) headtail_get_df(
year | le | |
---|---|---|
12 | 1911 | 52.6 |
13 | 1912 | 53.5 |
14 | 1913 | 52.5 |
15 | 1914 | 54.2 |
16 | 1915 | 54.5 |
Browse magic helpers
browse_df_params
browse_df_params (code, count, missing_config)
"", 10, 'pandas') browse_df_params(
(None, None, '', nan, True, True)
"y le* if year<1910, noformat", 50, '.') browse_df_params(
(None, ['year', 'le'], 'if year<1910', '.', True, False)
'in 1/5', 41, '.') browse_df_params(
(range(0, 5), None, '', '.', True, True)
*browse_df_params('in 1/5', obs_count(), '.')) get_df(
year | le | |
---|---|---|
1 | 1900 | 47.3 |
2 | 1901 | . |
3 | 1902 | 51.5 |
4 | 1903 | 50.5 |
5 | 1904 | 47.6 |
set_ipydatagrid_height
set_ipydatagrid_height ()
display_df_as_ipydatagrid
display_df_as_ipydatagrid (df, auto_height=True)
#set_ipydatagrid_height()
'gen long_name_1234567 = ""')
run_single('gen long_str = "10000000000200000000003000000000040000000000500000000006000000000070000000000800000000009000000000010000000000"') run_single(
(41 missing values generated)
= get_df(*browse_df_params(', noformat', obs_count(), '.'))
df display_df_as_ipydatagrid(df)
#set_ipydatagrid_height()
'sysuse auto, clear') run_single(
(1978 automobile data)
= get_df(*browse_df_params('', obs_count(), '.'))
df False) display_df_as_ipydatagrid(df,