Skip to content

Commit

Permalink
[GH-50] Pandas 1.0 compatible issue. (#51)
Browse files Browse the repository at this point in the history
Pandas 1.0 introduces a `_ensure_type` method that asserts the type of
`self` must be the same type as the input `obj`.  In this lib, the type
of `self` is `StockDataFrame` and the type of the object is `DataFrame`
which breaks this assert.

The temporary fix is to bypass the assert by override the `_ensure_type`
method in `StockDataFrame`.  The is just a work around.  The good news
is that the original method doesn't contain any business logic.

Other changes:
* Update the travis configuration to add CI for python 3.8.
* Drop the CI build for 3.4.  It's too old and takes too long to run.
  • Loading branch information
jealous committed Feb 1, 2020
1 parent 35f55b1 commit c236f9c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -2,10 +2,10 @@ language: python
dist: xenial
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
install:
- sudo apt-get install python-numpy
- sudo apt-get install python-pandas
Expand Down
10 changes: 9 additions & 1 deletion README.rst
Expand Up @@ -11,7 +11,7 @@ Stock Statistics/Indicators Calculation Helper
:target: https://pypi.python.org/pypi/stockstats


VERSION: 0.3.0
VERSION: 0.3.1

Introduction
------------
Expand Down Expand Up @@ -62,6 +62,13 @@ Installation

``pip install stockstats``

Compatibility
-------------

Please check the `setup.py`_ file.

Note that pandas add some type check after version 1.0.
One type assert is skipped in ``StockDataFrame``. Check ISSUE-50 for detail.

License
-------
Expand Down Expand Up @@ -260,3 +267,4 @@ Contact author:
- Cedric Zhuang <jealous@163.com>

.. _BSD: LICENSE.txt
.. _setup.py: setup.py
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -80,9 +80,10 @@ def get_long_description():
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Natural Language :: English",
"Intended Audience :: Developers",
Expand Down
7 changes: 7 additions & 0 deletions stockstats.py
Expand Up @@ -350,6 +350,13 @@ def _get_rsi(cls, df, n_days):
def _drop_columns(df, columns):
df.drop(columns, inplace=True, axis=1)

def _ensure_type(self, obj):
""" override the method in pandas, omit the check
This patch is not the perfect way but could make the lib work.
"""
return obj

@classmethod
def _get_smma(cls, df, column, windows):
""" get smoothed moving average.
Expand Down

0 comments on commit c236f9c

Please sign in to comment.