MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / test_dataframe_rows

Function test_dataframe_rows

pythonFiles/tests/ipython/test_variables.py:126–164  ·  view source on GitHub ↗
(capsys)

Source from the content-addressed store, hash-verified

124 not haveIPython, reason="Can't run variable tests without IPython console"
125)
126def test_dataframe_rows(capsys):
127 from IPython import get_ipython
128
129 # Setup some different types
130 path = os.path.dirname(os.path.abspath(__file__))
131 file = os.path.abspath(os.path.join(path, "random.csv"))
132 file = file.replace("\\", "\\\\")
133 dfstr = "import pandas as pd\r\ndf = pd.read_csv('{}')".format(file)
134 get_ipython().run_cell(dfstr)
135 vars = get_variables(capsys)
136 df = get_variable_value(vars, "df", capsys)
137 assert df
138 info = get_data_frame_info(vars, "df", capsys)
139 assert "rowCount" in info
140 assert info["rowCount"] == 6000
141 rows = get_data_frame_rows(info, 100, 200, capsys)
142 assert rows
143 assert rows["data"][0]["+h2"] == "Fy3 W[pMT["
144 get_ipython().run_cell(
145 """
146import pandas as pd
147import numpy as np
148ls = list([10, 20, 30, 40])
149df = pd.DataFrame(ls)
150se = pd.Series(ls)
151np1 = np.array(ls)
152np2 = np.array([[1, 2, 3], [4, 5, 6]])
153obj = {}
154"""
155 )
156 vars = get_variables(capsys)
157 np2 = get_variable_value(vars, "np2", capsys)
158 assert np2
159 info = get_data_frame_info(vars, "np2", capsys)
160 assert "rowCount" in info
161 assert info["rowCount"] == 2
162 rows = get_data_frame_rows(info, 0, 2, capsys)
163 assert rows
164 assert rows["data"][0]

Callers

nothing calls this directly

Calls 8

get_variablesFunction · 0.85
get_variable_valueFunction · 0.85
get_data_frame_infoFunction · 0.85
get_data_frame_rowsFunction · 0.85
joinMethod · 0.80
dirnameMethod · 0.65
formatMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected