mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-18 20:24:19 +01:00
Merge pull request #263 from hydrosquall/feature/validate-multi-ticker-pandas-arguments
[fix] Validate multi-ticker pandas arguments
This commit is contained in:
@@ -6,6 +6,8 @@ History
|
|||||||
0.10.x (2019-XX-XX)
|
0.10.x (2019-XX-XX)
|
||||||
------------------
|
------------------
|
||||||
* Documentation: Added a "Peer Comparison Analysis" Jupyter Notebook under "/examples" (@i3creations #197)
|
* Documentation: Added a "Peer Comparison Analysis" Jupyter Notebook under "/examples" (@i3creations #197)
|
||||||
|
* Minor: Update error message to clarify multiple tickers only work with single metrics
|
||||||
|
* Updated development dependencies
|
||||||
|
|
||||||
|
|
||||||
0.9.x (2019-01-30)
|
0.9.x (2019-01-30)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from unittest import TestCase
|
|||||||
import vcr
|
import vcr
|
||||||
|
|
||||||
from tiingo import TiingoClient
|
from tiingo import TiingoClient
|
||||||
from tiingo.api import InvalidFrequencyError
|
from tiingo.exceptions import InvalidFrequencyError
|
||||||
from tiingo.restclient import RestClientError
|
from tiingo.restclient import RestClientError
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import vcr
|
import vcr
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from tiingo import TiingoClient
|
from tiingo import TiingoClient
|
||||||
from tiingo.api import APIColumnNameError, InstallPandasException
|
from tiingo.exceptions import APIColumnNameError, InstallPandasException, MissingRequiredArgumentError
|
||||||
try:
|
try:
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
pandas_is_installed = True
|
pandas_is_installed = True
|
||||||
@@ -69,6 +69,10 @@ class TestTiingoWithPython(TestCase):
|
|||||||
self._client.get_dataframe(['GOOGL', 'AAPL'], startDate='2018-01-05',
|
self._client.get_dataframe(['GOOGL', 'AAPL'], startDate='2018-01-05',
|
||||||
endDate='2018-01-19', metric_name='xopen', frequency='weekly')
|
endDate='2018-01-19', metric_name='xopen', frequency='weekly')
|
||||||
|
|
||||||
|
def test_metric_name_missing_when_multiple_tickers(self):
|
||||||
|
with self.assertRaises(MissingRequiredArgumentError):
|
||||||
|
self._client.get_dataframe(['GOOGL', 'AAPL'], frequency='weekly')
|
||||||
|
|
||||||
@vcr.use_cassette('tests/fixtures/ticker_price_pandas_single.yaml')
|
@vcr.use_cassette('tests/fixtures/ticker_price_pandas_single.yaml')
|
||||||
def test_pandas_edge_case(self):
|
def test_pandas_edge_case(self):
|
||||||
"""Test single price/date being returned as a frame"""
|
"""Test single price/date being returned as a frame"""
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
from collections import namedtuple
|
||||||
import sys
|
|
||||||
import pkg_resources
|
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
from collections import namedtuple
|
import os
|
||||||
from zipfile import ZipFile
|
|
||||||
from tiingo.restclient import RestClient
|
|
||||||
import requests
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
import pkg_resources
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from tiingo.restclient import RestClient
|
||||||
|
from tiingo.exceptions import (
|
||||||
|
InstallPandasException,
|
||||||
|
APIColumnNameError,
|
||||||
|
InvalidFrequencyError,
|
||||||
|
MissingRequiredArgumentError)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -49,17 +56,6 @@ def dict_to_object(item, object_name):
|
|||||||
object_hook=lambda d:
|
object_hook=lambda d:
|
||||||
namedtuple(object_name, fields)(*values))
|
namedtuple(object_name, fields)(*values))
|
||||||
|
|
||||||
class InstallPandasException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class APIColumnNameError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidFrequencyError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TiingoClient(RestClient):
|
class TiingoClient(RestClient):
|
||||||
"""Class for managing interactions with the Tiingo REST API
|
"""Class for managing interactions with the Tiingo REST API
|
||||||
@@ -227,12 +223,16 @@ class TiingoClient(RestClient):
|
|||||||
frequency (string): Resample frequency (defaults to daily).
|
frequency (string): Resample frequency (defaults to daily).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
valid_columns = ['open', 'high', 'low', 'close', 'volume', 'adjOpen', 'adjHigh', 'adjLow',
|
valid_columns = {'open', 'high', 'low', 'close', 'volume', 'adjOpen', 'adjHigh', 'adjLow',
|
||||||
'adjClose', 'adjVolume', 'divCash', 'splitFactor']
|
'adjClose', 'adjVolume', 'divCash', 'splitFactor'}
|
||||||
|
|
||||||
if metric_name is not None and metric_name not in valid_columns:
|
if metric_name is not None and metric_name not in valid_columns:
|
||||||
raise APIColumnNameError('Valid data items are: ' + str(valid_columns))
|
raise APIColumnNameError('Valid data items are: ' + str(valid_columns))
|
||||||
|
|
||||||
|
if metric_name is None and isinstance(tickers, list):
|
||||||
|
raise MissingRequiredArgumentError("""When tickers is provided as a list, metric_name is a required argument.
|
||||||
|
Please provide a metric_name, or call this method with one ticker at a time.""")
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'resampleFreq': frequency
|
'resampleFreq': frequency
|
||||||
|
|||||||
14
tiingo/exceptions.py
Normal file
14
tiingo/exceptions.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Exception Clasess
|
||||||
|
class InstallPandasException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class APIColumnNameError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidFrequencyError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class MissingRequiredArgumentError(Exception):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user