question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PandasDataSource.update creates datasource with nan

See original GitHub issue

since v 1.5.1

Code that creates nans after ds merge

PandasDataSource.update()

input_df = pd.merge(input_df, df[[]], how='outer', left_index=True, right_index=True)

input_df = input_df.dropna() seems solves the issue

Steps to reproduce the issue:

  1. Set a breakpoint to the line described above
  2. Run example code and press u keypress to update ds
#!/usr/bin/env python3
from datetime import datetime, timedelta

import finplot as fplt
import yfinance as yf
from PyQt5.QtGui import QApplication, QGridLayout
from PyQt5.QtWidgets import QGraphicsView, QLabel

app = QApplication([])
win = QGraphicsView()
win.setWindowTitle('TradingView wannabe')
layout = QGridLayout()
win.setLayout(layout)
win.resize(600, 500)

info = QLabel()
layout.addWidget(info, 0, 1, 1, 1)

ax = fplt.create_plot()
win.axs = [ax] # finplot requres this property
layout.addWidget(ax.vb.win, 1, 0, 1, 2)

barsDate = datetime.fromisoformat("2021-03-12T21:15:55")
offset = timedelta(days=1)

def download(symbol):
    global barsDate
    items = yf.download(symbol, start=(barsDate).strftime("%Y-%m-%d"), end=(barsDate + offset).strftime("%Y-%m-%d"), interval='15m')
    print((barsDate + offset).strftime("%Y-%m-%d") + " - " + barsDate.strftime("%Y-%m-%d"))
    barsDate -= offset
    return items

plots = []
def update():
    df = download("AMD")
    if len(df) < 20: # symbol does not exist
        return
    price = df['Open Close High Low'.split()]
    if not plots:
        plots.append(fplt.candlestick_ochl(price))
    else:
        plots[0].update_data(price)

def _key_pressed(vb, ev):
    if ev.text() == 'u':
        update()

fplt._key_pressed = _key_pressed

update()
fplt.show(qt_exec=False) # prepares plots when they're all setup
win.show()
app.exec_()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
highfestivacommented, Mar 21, 2021

Many people ask for similar stuff, so added a reset functionality in 4a30ba28abd37a22155fef646f9003979ef61129. Use like so:

    price = df['Open Close High Low'.split()]
    ax.reset()
    fplt.candlestick_ochl(price)
    fplt.refresh()

No need to store plots for later, just reset and plot again. GL!

0reactions
highfestivacommented, Apr 5, 2021

I’ve included this functionality in an example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas: best practice to create multiple distinguishable ...
I have numeric timeseries data in a DataFrame, where individual columns are periodically updated from a live data source.
Read more >
How to modify values in a Pandas DataFrame?
Updating values in specific cells by index; Changing values in an entire DF row; Replace cells content according to condition; Modify values in...
Read more >
Simplify your Dataset Cleaning with Pandas | by Ulysse Petit
Extract relevant content from a Series; Check NaN values; Change the type of your Series. Open a new Jupyter notebook and import the...
Read more >
Working with missing data — pandas 1.5.2 documentation
In this section, we will discuss missing (also referred to as NA) values in pandas. Note. The choice of using NaN internally to...
Read more >
[BUG] vbar_stack with DataFrame as source ignores entire ...
When plotting a vbar_stack , the entire row in the data source is ignored if the first input column contains a NaN in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found