Data
For this demo, let's use the toy examples from the SandBonx folder that has some dummy scripts.
Import the DataPlotter class.
from ScanPyImports.plotter import DataPlotter
DataFrame of imported modules¶
The df attribute in the Data, DataAnalyzer, and DataPlotter classes retrieves the unprocessed data from the import statements in the dummy scripts (DataPlotter.df).
from ScanPyImports.plotter import DataPlotter
plotter = DataPlotter('../SandBox') # Set path to the SandBox folder on your computer.
df = plotter.df
print('Number of imports found:', len(df))
print('Packages:', df.imported_0.unique().tolist())
df.head(len(df))
Number of imports found: 10 Packages: ['sys', 'os', 'math', 'my_scripts', 'matplotlib', 'module1', 're', 'numpy']
imported_0 | imported_1 | alias | directory | extension | file | filename | original | path | |
---|---|---|---|---|---|---|---|---|---|
0 | sys | NaN | ../SandBox | py | module1.py | module1 | import sys, os | ../SandBox\module1.py | |
1 | os | NaN | ../SandBox | py | module1.py | module1 | import sys, os | ../SandBox\module1.py | |
2 | math | NaN | ../SandBox | py | module1.py | module1 | import math | ../SandBox\module1.py | |
3 | my_scripts | lookup_dir | look | ../SandBox | py | module2.py | module2 | from my_scripts import lookup_dir as look | ../SandBox\module2.py |
4 | matplotlib | pyplot | plt | ../SandBox | py | module2.py | module2 | import matplotlib.pyplot as plt | ../SandBox\module2.py |
5 | module1 | Class_1 | ../SandBox | py | module2.py | module2 | from module1 import Class_1 | ../SandBox\module2.py | |
6 | sys | NaN | ../SandBox\folder_1 | py | module3.py | module3 | import sys, os | ../SandBox\folder_1\module3.py | |
7 | os | NaN | ../SandBox\folder_1 | py | module3.py | module3 | import sys, os | ../SandBox\folder_1\module3.py | |
8 | re | NaN | ../SandBox\folder_1 | py | module3.py | module3 | import re | ../SandBox\folder_1\module3.py | |
9 | numpy | NaN | np | ../SandBox\folder_1 | py | module3.py | module3 | import numpy as np | ../SandBox\folder_1\module3.py |
For a brief description of the columns in the DataFrame, see DataPlotter.df.
In this example:
- module1 is a own-created module, which is a
py
script being imported by another script (module2
) located in the same directory. - All other packages are external packages.
Frequencies¶
To get the frequencies of the packages being imported, one can call the get_frequencies() function in the DataAnalyzer or DataPlotter class (DataPlotter.get_frequencies()).
plotter.get_frequencies()
Imports os 3 sys 3 math 2 matplotlib 1 my_scripts 1 numpy 1 re 1 dtype: int64
The process_own_modules
parameter¶
By default own-created modules are processed.
For more information on how own-created modules are processed, see own_processed_df
.
For getting the frequencies without processing own-created modules, set the argument process_own_modules
to False
plotter.get_frequencies(process_own_modules=False)
Imports os 2 sys 2 math 1 matplotlib 1 module1 1 my_scripts 1 numpy 1 re 1 dtype: int64
The exclude
parameter¶
To exclude some modules from the frequency analysis, you can assign a list of package names to the to_exclude
attribute.
plotter.to_exclude = ['my_scripts']
By default, the get_frequencies()
method excludes the packages listed in to_exclude
when calculating the frequencies.
Thus, my_scripts
will not be listed in the code below.
plotter.get_frequencies()
Imports os 3 sys 3 math 2 matplotlib 1 numpy 1 re 1 dtype: int64
If you wish to include them back in your analysis, set the exclude
argument to False
.
plotter.get_frequencies(exclude=False)
Imports os 3 sys 3 math 2 matplotlib 1 my_scripts 1 numpy 1 re 1 dtype: int64