Skip to content

Commit

Permalink
Fixing date types (quandl#110)
Browse files Browse the repository at this point in the history
* Fixing date types

* CP-6050: Extra space

* CP-6050: Testing

* CP-6050: conditional with some debug

* CP-6050: More testing

* CP-6050: Try to figure out why order is not correct

* CP-6050: Try to figure out why order is not correct

* CP-6050: Try to figure out why order is not correct

* CP-6050: Trying to fix order

* CP-6050: Try with objects

* CP-6050: Try with string

* CP-6050: Cleaned up code

* CP-6050: Numpy no longer supports Python v3.3

* CP-6050: Removed py3.3 from tests, bumbed version in tests

* CP-6050: Bumped minor version
  • Loading branch information
ericvautour-quandl authored Jul 3, 2018
1 parent 26ad37e commit fff2adc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ sudo: false
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 3.4.0 - 2018-07-03

* When returning a list of data, in a Python friendly format, convert datetime64 to datetime
* Numpy no longer supports Python v3.3, thus we are removing support for it

### 3.3.0 - 2017-12-20

* Unlock the version of requests to allow use with other modern packages
Expand Down
4 changes: 2 additions & 2 deletions quandl/model/data_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def to_pandas(self, keep_column_indexes=[]):
data = [data]
if 'columns' in self.meta.keys():
df = pd.DataFrame(data=data, columns=self.columns)
for index, type in enumerate(self.column_types):
if type == 'Date':
for index, column_type in enumerate(self.column_types):
if column_type == 'Date':
df[self.columns[index]] = df[self.columns[index]].apply(pd.to_datetime)
else:
df = pd.DataFrame(data=data, columns=self.column_names)
Expand Down
13 changes: 12 additions & 1 deletion quandl/model/merged_data_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .data_list import DataList
import numpy as np


class MergedDataList(DataList):
Expand All @@ -17,7 +18,17 @@ def to_pandas(self):
return self.__data_frame

def _initialize_raw_data(self):
return self.to_numpy().tolist()
numpy_results = self.to_numpy()
numpy_dtype_names = numpy_results.dtype.names

python_compatible_dtypes = []
for name in numpy_dtype_names:
if numpy_results.dtype[name].str == '<M8[ns]':
python_compatible_dtypes.append((str(name), np.dtype('<M8[ms]')))
else:
python_compatible_dtypes.append((str(name), numpy_results.dtype[name]))

return numpy_results.astype(python_compatible_dtypes).tolist()

def _column_names(self):
return self.to_numpy().dtype.names
2 changes: 1 addition & 1 deletion quandl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '3.3.0'
VERSION = '3.4.0'
2 changes: 1 addition & 1 deletion test/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ def test_build_request(self, mock):
'accept': ('application/json, '
'application/vnd.quandl+json;version=2015-04-09'),
'request-source': 'python',
'request-source-version': '3.3.0'},
'request-source-version': '3.4.0'},
params={'per_page': 10, 'page': 2})
self.assertEqual(mock.call_args, expected)
2 changes: 1 addition & 1 deletion test/test_merged_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_get_merged_dataset_data_to_list(self):
[datetime.datetime(2015, 7, 14, 0, 0), 437.5, 3, 437.5, 437.5, 3, 3],
[datetime.datetime(2015, 7, 15, 0, 0), 440.0, 2, 440.0, 440.0, 2, 3]]
for index, expected_item in enumerate(expected):
self.assertItemsEqual(results[index], expected_item)
self.assertItemsEqual(expected_item, results[index])

def test_get_merged_dataset_data_is_descending_when_specified_in_params(self):
data = MergedDataset(['NSE/OIL', 'WIKI/AAPL',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py2.7,py3.3,py3.4,py3.5,py3.6
envlist = py2.7,py3.4,py3.5,py3.6

[testenv]
commands =
Expand Down

0 comments on commit fff2adc

Please sign in to comment.