Skip to content

Commit a58eeff

Browse files
authored
Format Python files with Black (#9742)
* Format Python files with black (exclude test data) * Fix DS test * More DS test fixing
1 parent d788d18 commit a58eeff

46 files changed

Lines changed: 5277 additions & 4550 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pythonFiles/completion.py

Lines changed: 254 additions & 214 deletions
Large diffs are not rendered by default.

pythonFiles/datascience/daemon/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
LOG_FORMAT = "%(asctime)s UTC - %(levelname)s - %(name)s - %(message)s"
1515
queue_handler = None
1616

17+
1718
def add_arguments(parser):
1819
parser.description = "Daemon"
1920

@@ -47,16 +48,19 @@ class TemporaryQueueHandler(logging.Handler):
4748
Later the messages are pushed back to the RPC client as a notification.
4849
Once the RPC channel is up, we'll stop queuing messages and sending id directly.
4950
"""
51+
5052
def __init__(self):
5153
logging.Handler.__init__(self)
5254
self.queue = []
5355
self.server = None
56+
5457
def set_server(self, server):
5558
# Send everything that has beeen queued until now.
5659
self.server = server
5760
for msg in self.queue:
5861
self.server._endpoint.notify("log", msg)
5962
self.queue = []
63+
6064
def emit(self, record):
6165
data = {"level": record.levelname, "msg": self.format(record)}
6266
# If we don't have the server, then queue it and send it later.

pythonFiles/datascience/daemon/daemon_output.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,3 @@ def redirect_output(stdout_handler, stderr_handler):
128128
_stderr_redirector = sys.stderr = IORedirector(
129129
"stderr", sys.stderr, sys._vsc_err_buffer_, True
130130
)
131-

pythonFiles/datascience/daemon/daemon_python.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ class PythonDaemon(MethodDispatcher):
6767
"""
6868

6969
def __init__(self, rx, tx):
70-
self.log = logging.getLogger("{0}.{1}".format(self.__class__.__module__,self.__class__.__name__))
70+
self.log = logging.getLogger(
71+
"{0}.{1}".format(self.__class__.__module__, self.__class__.__name__)
72+
)
7173
self._jsonrpc_stream_reader = JsonRpcStreamReader(rx)
7274
self._jsonrpc_stream_writer = JsonRpcStreamWriter(tx)
7375
self._endpoint = Endpoint(

pythonFiles/datascience/dummyJupyter.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
import argparse
55
import time
66

7+
78
def main():
8-
print('hello from dummy jupyter')
9+
print("hello from dummy jupyter")
910
parser = argparse.ArgumentParser()
10-
parser.add_argument('--version', type=bool, default=False, const=True, nargs='?')
11-
parser.add_argument('notebook', type=bool, default=False, const=True, nargs='?')
12-
parser.add_argument('--no-browser', type=bool, default=False, const=True, nargs='?')
13-
parser.add_argument('--notebook-dir', default='')
14-
parser.add_argument('--config', default='')
11+
parser.add_argument("--version", type=bool, default=False, const=True, nargs="?")
12+
parser.add_argument("notebook", type=bool, default=False, const=True, nargs="?")
13+
parser.add_argument("--no-browser", type=bool, default=False, const=True, nargs="?")
14+
parser.add_argument("--notebook-dir", default="")
15+
parser.add_argument("--config", default="")
1516
results = parser.parse_args()
16-
if (results.version):
17-
print('1.1.dummy')
17+
if results.version:
18+
print("1.1.dummy")
1819
else:
19-
print('http://localhost:8888/?token=012f08663a68e279fe0a5335e0b5dfe44759ddcccf0b3a56')
20+
print(
21+
"http://localhost:8888/?token=012f08663a68e279fe0a5335e0b5dfe44759ddcccf0b3a56"
22+
)
2023
time.sleep(5)
21-
raise Exception('Dummy is dead')
24+
raise Exception("Dummy is dead")
2225

2326

24-
if __name__ == '__main__':
27+
if __name__ == "__main__":
2528
main()

pythonFiles/datascience/getJupyterKernels.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88

99
specs = jupyter_client.kernelspec.KernelSpecManager().get_all_specs()
10-
all_specs = {
11-
"kernelspecs": specs
12-
}
10+
all_specs = {"kernelspecs": specs}
1311

1412
sys.stdout.write(json.dumps(all_specs))
1513
sys.stdout.flush()

pythonFiles/datascience/getJupyterVariableDataFrameInfo.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88

99
# In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
1010
# Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
11-
_VSCODE_targetVariable = _VSCODE_json.loads('_VSCode_JupyterTestValue')
11+
_VSCODE_targetVariable = _VSCODE_json.loads("""_VSCode_JupyterTestValue""")
1212

1313
# First check to see if we are a supported type, this prevents us from adding types that are not supported
1414
# and also keeps our types in sync with what the variable explorer says that we support
15-
if _VSCODE_targetVariable['type'] not in _VSCode_supportsDataExplorer:
15+
if _VSCODE_targetVariable["type"] not in _VSCode_supportsDataExplorer:
1616
del _VSCode_supportsDataExplorer
1717
print(_VSCODE_json.dumps(_VSCODE_targetVariable))
1818
del _VSCODE_targetVariable
1919
else:
2020
del _VSCode_supportsDataExplorer
21-
_VSCODE_evalResult = eval(_VSCODE_targetVariable['name'])
21+
_VSCODE_evalResult = eval(_VSCODE_targetVariable["name"])
2222

2323
# Figure out shape if not already there. Use the shape to compute the row count
24-
if (hasattr(_VSCODE_evalResult, 'shape')):
24+
if hasattr(_VSCODE_evalResult, "shape"):
2525
try:
2626
# Get a bit more restrictive with exactly what we want to count as a shape, since anything can define it
2727
if isinstance(_VSCODE_evalResult.shape, tuple):
28-
_VSCODE_targetVariable['rowCount'] = _VSCODE_evalResult.shape[0]
28+
_VSCODE_targetVariable["rowCount"] = _VSCODE_evalResult.shape[0]
2929
except TypeError:
30-
_VSCODE_targetVariable['rowCount'] = 0
31-
elif (hasattr(_VSCODE_evalResult, '__len__')):
30+
_VSCODE_targetVariable["rowCount"] = 0
31+
elif hasattr(_VSCODE_evalResult, "__len__"):
3232
try:
33-
_VSCODE_targetVariable['rowCount'] = len(_VSCODE_evalResult)
33+
_VSCODE_targetVariable["rowCount"] = len(_VSCODE_evalResult)
3434
except TypeError:
35-
_VSCODE_targetVariable['rowCount'] = 0
35+
_VSCODE_targetVariable["rowCount"] = 0
3636

3737
# Turn the eval result into a df
3838
_VSCODE_df = _VSCODE_evalResult
@@ -43,16 +43,18 @@
4343
elif isinstance(_VSCODE_evalResult, dict):
4444
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
4545
_VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
46-
elif _VSCODE_targetVariable['type'] == 'ndarray':
46+
elif _VSCODE_targetVariable["type"] == "ndarray":
4747
_VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
4848

4949
# If any rows, use pandas json to convert a single row to json. Extract
5050
# the column names and types from the json so we match what we'll fetch when
5151
# we ask for all of the rows
52-
if _VSCODE_targetVariable['rowCount']:
52+
if _VSCODE_targetVariable["rowCount"]:
5353
try:
5454
_VSCODE_row = _VSCODE_df.iloc[0:1]
55-
_VSCODE_json_row = _VSCODE_pd_json.to_json(None, _VSCODE_row, date_format='iso')
55+
_VSCODE_json_row = _VSCODE_pd_json.to_json(
56+
None, _VSCODE_row, date_format="iso"
57+
)
5658
_VSCODE_columnNames = list(_VSCODE_json.loads(_VSCODE_json_row))
5759
del _VSCODE_row
5860
del _VSCODE_json_row
@@ -62,24 +64,24 @@
6264
_VSCODE_columnNames = list(_VSCODE_df)
6365

6466
# Compute the index column. It may have been renamed
65-
_VSCODE_indexColumn = _VSCODE_df.index.name if _VSCODE_df.index.name else 'index'
67+
_VSCODE_indexColumn = _VSCODE_df.index.name if _VSCODE_df.index.name else "index"
6668
_VSCODE_columnTypes = list(_VSCODE_df.dtypes)
6769
del _VSCODE_df
6870

6971
# Make sure the index column exists
7072
if _VSCODE_indexColumn not in _VSCODE_columnNames:
7173
_VSCODE_columnNames.insert(0, _VSCODE_indexColumn)
72-
_VSCODE_columnTypes.insert(0, 'int64')
74+
_VSCODE_columnTypes.insert(0, "int64")
7375

7476
# Then loop and generate our output json
7577
_VSCODE_columns = []
7678
for _VSCODE_n in range(0, len(_VSCODE_columnNames)):
7779
_VSCODE_column_type = _VSCODE_columnTypes[_VSCODE_n]
7880
_VSCODE_column_name = str(_VSCODE_columnNames[_VSCODE_n])
7981
_VSCODE_colobj = {}
80-
_VSCODE_colobj['key'] = _VSCODE_column_name
81-
_VSCODE_colobj['name'] = _VSCODE_column_name
82-
_VSCODE_colobj['type'] = str(_VSCODE_column_type)
82+
_VSCODE_colobj["key"] = _VSCODE_column_name
83+
_VSCODE_colobj["name"] = _VSCODE_column_name
84+
_VSCODE_colobj["type"] = str(_VSCODE_column_type)
8385
_VSCODE_columns.append(_VSCODE_colobj)
8486
del _VSCODE_column_name
8587
del _VSCODE_column_type
@@ -88,12 +90,11 @@
8890
del _VSCODE_columnTypes
8991

9092
# Save this in our target
91-
_VSCODE_targetVariable['columns'] = _VSCODE_columns
92-
_VSCODE_targetVariable['indexColumn'] = _VSCODE_indexColumn
93+
_VSCODE_targetVariable["columns"] = _VSCODE_columns
94+
_VSCODE_targetVariable["indexColumn"] = _VSCODE_indexColumn
9395
del _VSCODE_columns
9496
del _VSCODE_indexColumn
9597

96-
9798
# Transform this back into a string
9899
print(_VSCODE_json.dumps(_VSCODE_targetVariable))
99100
del _VSCODE_targetVariable

pythonFiles/datascience/getJupyterVariableDataFrameRows.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
# In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
77
# Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
8-
_VSCODE_targetVariable = _VSCODE_json.loads('_VSCode_JupyterTestValue')
9-
_VSCODE_evalResult = eval(_VSCODE_targetVariable['name'])
8+
_VSCODE_targetVariable = _VSCODE_json.loads("""_VSCode_JupyterTestValue""")
9+
_VSCODE_evalResult = eval(_VSCODE_targetVariable["name"])
1010

1111
# _VSCode_JupyterStartRow and _VSCode_JupyterEndRow should be replaced dynamically with the literals
1212
# for our start and end rows
1313
_VSCODE_startRow = max(_VSCode_JupyterStartRow, 0)
14-
_VSCODE_endRow = min(_VSCode_JupyterEndRow, _VSCODE_targetVariable['rowCount'])
14+
_VSCODE_endRow = min(_VSCode_JupyterEndRow, _VSCODE_targetVariable["rowCount"])
1515

1616
# Assume we have a dataframe. If not, turn our eval result into a dataframe
1717
_VSCODE_df = _VSCODE_evalResult
@@ -22,15 +22,17 @@
2222
elif isinstance(_VSCODE_evalResult, dict):
2323
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
2424
_VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
25-
elif _VSCODE_targetVariable['type'] == 'ndarray':
25+
elif _VSCODE_targetVariable["type"] == "ndarray":
2626
_VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
2727
# If not a known type, then just let pandas handle it.
28-
elif not (hasattr(_VSCODE_df, 'iloc')):
28+
elif not (hasattr(_VSCODE_df, "iloc")):
2929
_VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
3030

3131
# Turn into JSON using pandas. We use pandas because it's about 3 orders of magnitude faster to turn into JSON
3232
_VSCODE_rows = _VSCODE_df.iloc[_VSCODE_startRow:_VSCODE_endRow]
33-
_VSCODE_result = _VSCODE_pd_json.to_json(None, _VSCODE_rows, orient='table', date_format='iso')
33+
_VSCODE_result = _VSCODE_pd_json.to_json(
34+
None, _VSCODE_rows, orient="table", date_format="iso"
35+
)
3436
print(_VSCODE_result)
3537

3638
# Cleanup our variables

pythonFiles/datascience/getJupyterVariableList.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
_VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']"
99

1010
# who_ls is a Jupyter line magic to fetch currently defined vars
11-
_VSCode_JupyterVars = _VSCODE_get_ipython().run_line_magic('who_ls', '')
11+
_VSCode_JupyterVars = _VSCODE_get_ipython().run_line_magic("who_ls", "")
1212

1313
_VSCode_output = []
1414
for _VSCode_var in _VSCode_JupyterVars:
1515
try:
1616
_VSCode_type = type(eval(_VSCode_var))
17-
_VSCode_output.append({'name': _VSCode_var, 'type': _VSCode_type.__name__, 'size': _VSCODE_getsizeof(_VSCode_var), 'supportsDataExplorer': _VSCode_type.__name__ in _VSCode_supportsDataExplorer })
17+
_VSCode_output.append(
18+
{
19+
"name": _VSCode_var,
20+
"type": _VSCode_type.__name__,
21+
"size": _VSCODE_getsizeof(_VSCode_var),
22+
"supportsDataExplorer": _VSCode_type.__name__
23+
in _VSCode_supportsDataExplorer,
24+
}
25+
)
1826
del _VSCode_type
1927
del _VSCode_var
2028
except:

0 commit comments

Comments
 (0)