<jupyter_start><jupyter_text>Using the EnvHandler class By the end of this tutorial you should be able to do the following:            Create an instance of the EnvHandler class for a given python object.                                    Use the display_as, df_args and df_kwargs parameters of                     EnvHandler (EnvHandler.__init__) to customise the EnvHandler.                            Use the update method to update an instance of the EnvHandler class inplace.    Use the subenv method to create EnvHandler             instances from objects stored withing an EnvHandler.<jupyter_code>from env_explore import EnvHandler<jupyter_output><empty_output><jupyter_text>An instance of class the  `ExampleClass`, from ``tutorial_utils`` will be used thoughout this tutorial.<jupyter_code>from tutorial_utils import ExampleClass
eg = ExampleClass()<jupyter_output><empty_output><jupyter_text>**1** - Create an instance of the ``EnvHandler`` class for a given python object.The minimimum input required is the ``name`` argument.  This is a string that can be evaluated as code in the current enviromentto create the ``env`` attribute.The code below creates an EnvHandler for the ``ExampleClass`` instance, ``eg`` using all given parameter defaults.<jupyter_code>eh = EnvHandler('eg')
eh<jupyter_output><empty_output><jupyter_text>**1.a** - Use parameters to customise the EnvHandler``name`` (``str``): Name by which the object can be referenced in the main enviroment.    ``display_as`` (``str``): Name of the attribute to be displayed by the ``_ipython_display_`` method (default = ``'df'``).``df_args`` (``Iterable``): Positional arguments for ``self.setdf`` (default = ``{}``). ``df_kwargs`` (``dict``): Key word arguments for ``self.setdf`` (default = ``{}``).    ``html_args`` (``Iterable``): Positional arguments for ``self.sethtml`` (default = ``[]``).    ``html_kwargs`` (``dict``): Key word arguments for ``self.sethtml`` (default = ``{}``).  **1.a. Example 1** - Create an EnvHandler which is displayed as a dictionaryThe ``display_as`` argument can be used to determine how the EnvHandler will be displayed (using the ``_ipython_display_`` method).The code below creates an EnvHandler for the ``ExampleClass`` instance, ``eg`` which is displayed as a dictionary.<jupyter_code>EnvHandler(
    name='eg',
    display_as='dicti' # 'dicti' is the name of an attribute of the EnvHandler
)<jupyter_output><empty_output><jupyter_text>**1.a. Example 2** - Choose the columns of the EnvHandlerThe ``df_kwargs`` or (``df_args``) argument can be used to determine the columns in the ``EnvHandler.df`` DataframeThe code below creates an EnvHandler for the ``ExampleClass`` instance, ``eg`` which has extra columns.<jupyter_code>df_kwargs = {
    'funcs': {'Type': type, 'Times 2': lambda x: x*2},  # {column_name: function}
    'attrs': {'Documentation': '__doc__', 'Real': 'real'}  # {column_name: attribute_name}
}

df_args = df_kwargs.values()

# the two objects displayed should be identical
display(
    EnvHandler('eg', df_kwargs=df_kwargs), # using df_kwargs
    EnvHandler('eg', df_args=df_args) # using df_args
)<jupyter_output><empty_output><jupyter_text>**2** - Using the ``update`` methodIf the result of evaluating the ``name`` attribute changes, the ``update`` method can be used to update the EnvHandler accordingly.``update`` both returns an updated instance of the EnvHandler and updates it inplace.Note that ``name``, ``df_args`` and ``df_kwargs`` arguments used to create an EnvHandler in 1.a. Example 2 can be used in the same way by ``update``.The code below will set a new attribute, ``f``, of our ``ExampleClass`` instance ``eg`` with value ``'New Attribute'`` before calling the ``update``.  Notice how our EnvHandler ``eh`` now has an extra row with index ``'f'``.<jupyter_code>eg.f = 'New Attribute'
eh.update()<jupyter_output><empty_output><jupyter_text>**3** - Using the ``subenv`` methodThe subenv method can be used to create an EnvHandler from an attribute of the ``env`` of an existing EnvHandler.Note that ``df_args`` and ``df_kwargs`` arguments used to create an EnvHandler in 1.a. Example 2 can be used in the same way by ``update``.  **3 Example 1** - Use the update method to create an EnvHandler from ``eg.b``.<jupyter_code>eh.subenv('b') # roughly equivilant to EnvHandler('eg.b')<jupyter_output><empty_output><jupyter_text>**3 Example 2** - Use the update method to create an EnvHandler from ``eg.a.imag``.<jupyter_code>eh.subenv(['a', 'imag']) # roughly equivilant to EnvHandler('eg.b.imag')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12489063867016623, 'fraction_numerical': 0.003937007874015748, 'mean_word_length': 5.025032938076416, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '473520', 'license': 'MIT', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1307, 'n_words': 516, 'path': 'tutorials/EnvHandler_tutorial.ipynb', 'repo_name': 'nuki111/env_explore', 'size': '4572'}