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

Datasources - Small refactoring #260

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions orangecontrib/timeseries/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ def windowed_cumprod(x, width, shift):

def windowed_mode(x, width, shift):
modes, counts = windowed_func(
partial(stats.mode, nan_policy='omit'),
# keepdims argument can be removed when we require scipy>=1.11
partial(stats.mode, nan_policy='omit', keepdims=False),
x, width, shift)
modes = modes[:, 0]
if np.ma.isMaskedArray(modes):
# If counts == 0, all values were nan
modes = modes.data
modes[counts[:, 0] == 0] = np.nan
modes[counts == 0] = np.nan
return modes


Expand Down
27 changes: 6 additions & 21 deletions orangecontrib/timeseries/datasources.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
from datetime import date
import logging
from datetime import date

import pandas_datareader.data as web

import yfinance as yf
from Orange.data import Domain
from Orange.data.pandas_compat import table_from_frame
from pandas_datareader import data as pdr

from Orange.data import Domain
from orangecontrib.timeseries import Timeseries

import yfinance as yf

log = logging.getLogger(__name__)

try:
from Orange.data.pandas_compat import table_from_frame
except ImportError:
raise RuntimeError("Yahoo Finance requires Orange >= 3.9")


def quandl_data(symbol,
since=None,
Expand Down Expand Up @@ -55,11 +48,7 @@ def quandl_data(symbol,
return ts



def finance_data(symbol,
since=None,
until=None,
granularity='d'):
def finance_data(symbol, since=None, until=None):
"""Fetch Yahoo Finance data for stock or index `symbol` within the period
after `since` and before `until` (both inclusive).

Expand All @@ -71,8 +60,6 @@ def finance_data(symbol,
A start date (default: 1900-01-01).
until: date
An end date (default: today).
granularity: 'd' or 'w' or 'm' or 'v'
What data to get: daily, weekly, monthly, or dividends.

Returns
-------
Expand All @@ -91,9 +78,7 @@ def finance_data(symbol,
# Make Adjusted Close a class variable
attrs = [var.name for var in data.domain.attributes]
attrs.remove('Adj Close')
data = Timeseries.from_table(Domain(attrs, [data.domain['Adj Close']],
None, source=data.domain),
data)
data = data.transform(Domain(attrs, [data.domain['Adj Close']], source=data.domain))

data.name = symbol
data.time_variable = data.domain['Date']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
'pandas', # statsmodels requires this but doesn't have it in dependencies?
'pandas_datareader',
'numpy',
'scipy>=0.17',
'scipy>=1.9.2',
'more-itertools',
# required to get current timezone
# adding it does not hurt, Pandas have it as a dependency
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ deps =
# orange3 requires the following
oldest: orange-widget-base==4.18.0
oldest: orange-canvas-core==0.1.27
oldest: scipy==1.9.2
latest: https://github.com/biolab/orange3/archive/refs/heads/master.zip#egg=orange3
latest: https://github.com/biolab/orange-canvas-core/archive/refs/heads/master.zip#egg=orange-canvas-core
latest: https://github.com/biolab/orange-widget-base/archive/refs/heads/master.zip#egg=orange-widget-base
Expand Down
Loading