Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize IEX_Trading #398

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Modernize IEX_Trading #398

wants to merge 7 commits into from

Conversation

jtao1
Copy link
Collaborator

@jtao1 jtao1 commented Jun 12, 2024

Modernizing an example checklist

Preliminary checks

  • Look for open PRs and issues that reference the project you are updating. It is possible previous unmerged work in PR could be re-used to modernize the project. Comment on these PRs and issues when appropriate, hopefully we should be able to close some of them after your modernizing work.

Change ‘anaconda-project.yml’ to use the latest workable version of packages

  • Pin python=3.11
  • Remove the upper pin (e.g. hvplot<0.9 to hvplot, panel>=0.12,<1.0 to panel>=0.12) of all other dependencies. Removing the upper pins of dependencies could necessitate code revisions in the notebooks to address any errors encountered in the updated environment. Should complexities or extensive time requirements arise, document issues for team discussion on whether to re-pin specific packages or explore other solutions.
  • Add/update the lower pin of all other dependencies (e.g. hvplot to hvplot>=0.9.2, hvplot>=0.8 to hvplot>=0.9.2). Usually, the new/updated lower pin of a dependency will be the version resolved after anaconda prepare has been run. Execute !conda list in a notebook, or anaconda run conda list in the terminal, to display the version of each dependency installed in the environment. Adjusting the lower pin helps ensure that the locks produced for each platform (linux-64, win-64, osx-64, osx-arm64) rely on the tested dependencies and not on some older versions.
  • If one of the channels include conda-forge or pyviz, ask Maxime if it can be removed

Plot API updates (discussed on a per-example basis)

  • Generally, try to replace HoloViews usage with hvPlot. At a certain point of complexity, such as with the use of ‘.select’, it might be better to stick with HoloViews. Additional examples of ‘complexity boundaries’ should be documented in this document.
  • Almost always, try to replace the use of datashade with rasterize (read this page). Essentially, rasterize allows Bokeh to handle the colormapping instead of Datashader.

Interactivity API updates (discussed on a per-example basis)

  • Remove all pn.interact usage
  • Avoid .param.watch() usage. This is pretty low-level and verbose approach and should not be used in Examples unless required, or an Example is specifically trying to demo its usage in an advanced workflow.
  • Prefer using pn.bind(). Read this page for explanation.
  • For apps built using a class approach, when they create a view() method and call it directly, update the class by inheriting from pn.viewable.Viewer and replace view() by __panel__(). Here is an example.

Panel App updates (discussed on a per-example basis)

  • If the project doesn’t at any point create a Panel app at all, consider creating one. It can be as simple as wrapping a plot in pn.Column, or more complicated to incorporate widgets, etc. Make the final app .servable().
  • If the project creates an app in a notebook but doesn’t deploy it (i.e. there is no command: dashboard declaration in the anaconda-project.yml file), try adding it.
  • If the project already deploys an app but doesn’t wrap it in a nice template, consider wrapping it in a template.
  • If the project deploys an app wrapped in a template, customize the template a little so all the apps don’t look similar (e.g. change the header background color). This doesn’t need to be discussed.
  • Comment start If you are building the application in a single cell, you can construct a template explicitly, like template = pn.template.BootstrampTemplate, but if building up an app across multiple cells, it is probably cleaner to declare the template at the top with pn.extension(template='bootstrap'). See how to guide on setting a template.

General code quality updates

  • If the notebook disables warnings (e.g. with warnings.simplefilter(‘ignore’) somewhere at the start of the notebook, remove this line. Try to update the code to remove the warnings, if any. If updating the code to remove the warnings is taking significant amount of time and effort, bring it up for discussion and we may decide to disable warnings again.

Text content

  • Edit the text content anywhere and everywhere that it can be improved for clarity.
  • Check the links are valid, and update old links (e.g. http -> https, xyz.pyviz.org -> xyz.holoviz.org)
  • Remove instructions to install packages inside an example

Visual appearance - Example

  • Check that the titles/headings make sense and are succinct.
  • Check that the text content blocks are easily readable; revise into additional paragraphs if needed.
  • Check that the code blocks are easily readable; revise as needed. (e.g. add spaces after commas in a list if there are none, wrap long lines, etc.)
  • Check image and plot sizes. If possible, making them responsive is highly recommended.
  • Check the appearance on a smartphone (check Google to see how to adapt the appearance of your browser to display pages as if they were seen from a smartphone, this is usually done via the web developer tools). This is not a top priority for all examples, but if there are a few easy and straightforward changes to make that can improve the experience, let’s do it.
  • Check the updated notebook with the original notebook

Visual appearance - Gallery

  • Check the thumbnail is visually appealing
  • Check the project title is well formatted (e.g. Ml Annotators to ML Annotators), if not, add/update the examples_config.title field in anaconda-project.yml
  • Check the project description is appropriate, if not, update the description field in anaconda-project.yml

Workflow (after you have made the changes above)

  • Run successfully doit validate:<projectname>
  • Run successfully doit test:<projectname>
  • Run successfully doit doc_one –name <projectname>. It’s better if the project notebook(s) is saved with its outputs (but be sure to clear outputs before committing to the examples repo!) when building the docs. Then open this file in your browser ./builtdocs/index.html and check how the site looks.
  • If you’re happy with all the above, open a PR. Reminder, clear notebook outputs before pushing to the PR.

@jtao1
Copy link
Collaborator Author

jtao1 commented Jun 12, 2024

Not ready for review yet, just showing initial progress made.

@Azaya89 Azaya89 added the NF SDG NumFocus Software Development Grant 2024 label Jun 12, 2024
Copy link
Contributor

Your changes were successfully integrated in the dev site, make sure to review
the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/.
You can also download an archive of the site from the workflow summary page which comes in handy
when your dev site built was overriden by another PR (we have a single dev site!).

@droumis
Copy link
Contributor

droumis commented Jun 26, 2024

@jtao1 please check for typos

e.g. in the first section of the first notebook:

"datashader via the HoloViewsAPI."

should be:

"Datashader via the HoloViews API."

@droumis
Copy link
Contributor

droumis commented Jun 26, 2024

Please try to replace the use of a Bokeh custom hover tool with HoloViews hover_tooltips

@droumis
Copy link
Contributor

droumis commented Jun 26, 2024

more typos:

"Note: If you display the spikes object at this time, it will probably freeze or crash your browser tb!"

"We will use the responsive=True option to make our rasters fill the scren:"

@jtao1
Copy link
Collaborator Author

jtao1 commented Jul 17, 2024

In IEX_stocks, the plots display as intended, but I don't know how to get rid of the warnings. I am running into an conversion issue between DateTime and Floats. I tried converting the timestamps which are of type DateTime into floats but that didn't work as it led to a similar issue.

Traceback
```WARNING:param.dynamic_operation: Callable raised "UFuncTypeError(<ufunc 'less_equal'>, (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes.Float64DType'>, None))".
Invoked as dynamic_operation(x_range=(nan, nan))
WARNING:param.dynamic_operation: Callable raised "UFuncTypeError(<ufunc 'less_equal'>, (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes.Float64DType'>, None))".
Invoked as dynamic_operation(x_range=(nan, nan))
numpy.exceptions.DTypePromotionError: The DType <class 'numpy.dtypes.DateTime64DType'> could not be promoted by <class 'numpy.dtypes.Float64DType'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes.Float64DType'>)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/plotting/util.py", line 293, in get_plot_frame
    return map_obj[key]
           ~~~~~~~^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1038, in dynamic_operation
    key, obj = resolve(key, kwargs)
               ^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1027, in resolve
    return key, map_obj[key]
                ~~~~~~~^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1038, in dynamic_operation
    key, obj = resolve(key, kwargs)
               ^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1027, in resolve
    return key, map_obj[key]
                ~~~~~~~^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1038, in dynamic_operation
    key, obj = resolve(key, kwargs)
               ^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1027, in resolve
    return key, map_obj[key]
                ~~~~~~~^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 197, in dynamic_mul
    self_el = self.select(HoloMap, **key_map) if self.kdims else self[()]
                                                                 ~~~~^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 197, in dynamic_mul
    self_el = self.select(HoloMap, **key_map) if self.kdims else self[()]
                                                                 ~~~~^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 581, in __call__
    ret = self.callable(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1038, in dynamic_operation
    key, obj = resolve(key, kwargs)
               ^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1027, in resolve
    return key, map_obj[key]
                ~~~~~~~^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/spaces.py", line 581, in __call__
    ret = self.callable(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1039, in dynamic_operation
    return apply(obj, *key, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1031, in apply
    processed = self._process(element, key, kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/util/__init__.py", line 1013, in _process
    return self.p.operation.process_element(element, key, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/operation.py", line 194, in process_element
    return self._apply(element, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/core/operation.py", line 141, in _apply
    ret = self._process(element, key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/operation/datashader.py", line 682, in _process
    info = self._get_sampling(element, x, y, ndim=1, default=default)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/holoviews/operation/resample.py", line 141, in _get_sampling
    x_range = (np.nanmin([np.nanmax([x0, ex0]), ex1]),
                          ^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/numpy/lib/nanfunctions.py", line 483, in nanmax
    res = np.amax(a, axis=axis, out=out, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 2827, in amax
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/Impor/holoviz-examples/examples/iex_trading/envs/default/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 88, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.core._exceptions._UFuncNoLoopError: ufunc 'less_equal' did not contain a loop with signature matching types (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes.Float64DType'>) -> None```

Copy link
Contributor

Your changes were successfully integrated in the dev site, make sure to review
the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/.
You can also download an archive of the site from the workflow summary page which comes in handy
when your dev site built was overriden by another PR (we have a single dev site!).

@droumis
Copy link
Contributor

droumis commented Jul 17, 2024

try df['col'] = df['col'].tz_localize('UTC') or df['col'] = df['col'].tz_localize(None) ... not sure if this is the actual issue

@Azaya89 Azaya89 requested review from droumis and maximlt July 24, 2024 12:50
@Azaya89 Azaya89 self-requested a review August 6, 2024 20:56
Copy link
Contributor

github-actions bot commented Aug 7, 2024

Your changes were successfully integrated in the dev site, make sure to review
the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/.
You can also download an archive of the site from the workflow summary page which comes in handy
when your dev site built was overriden by another PR (we have a single dev site!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NF SDG NumFocus Software Development Grant 2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants