Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pinkfish package
#1
I am trying to install the "pinkish" package.

in Anaconda navigator ---> environments -----> base(root)
I already installed "pinkish" package.

but when I am running the code:

import pandas as pd
import numpy as np
import os
from pandas import DataFrame
from datetime import datetime
import matplotlib.pyplot as plt
import csv
import requests
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib as mpl
%matplotlib inline
from matplotlib.pylab import rcParams
import seaborn as sns
import pandas_datareader as dr
#
#
import pinkfish as pf
#
#
Error:
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-6-52c4b54f7601> in <module> ----> 1 import pinkfish as pf D:\programs\anaconda3\lib\site-packages\pinkfish\__init__.py in <module> ----> 1 from pinkfish.fetch import (fetch_timeseries, select_tradeperiod) 2 from pinkfish.trade import (TradeLog, TradeState, DailyBal) 3 from pinkfish.statistics import (stats, summary, summary2, summary3) 4 from pinkfish.benchmark import (Benchmark) 5 from pinkfish.plot import (plot_equity_curve, plot_trades, plot_bar_graph) D:\programs\anaconda3\lib\site-packages\pinkfish\fetch.py in <module> 13 # Other imports 14 import pandas as pd ---> 15 from pandas.io.data import DataReader 16 import datetime 17 import os ModuleNotFoundError: No module named 'pandas.io.data'
what would be solutions?
Reply
#2
Issue report
Reply
#3
I understand the pandas.io.data is removed.
I installed the pink fish 0.5.1 which is the latest version

I installed both
pandas 1.0.1
pandas-datareader 0.8.1

I am new to programming.
I don't think i can edit the package?

what would be the workaround?

(May-15-2020, 06:20 AM)snippsat Wrote: Issue report
Reply
#4
Do pip install pandas_datareader
Now open file D:\programs\anaconda3\lib\site-packages\pinkfish\fetch.py.
Change and save.
#from pandas.io.data import DataReader
from pandas_datareader.data import DataReader
Now will import pinkfish as pf work,it give deprecated Waring,but that can just ignore.
Reply
#5
You are amazing. this worked.

(May-15-2020, 06:31 PM)snippsat Wrote: Do pip install pandas_datareader
Now open file D:\programs\anaconda3\lib\site-packages\pinkfish\fetch.py.
Change and save.
#from pandas.io.data import DataReader
from pandas_datareader.data import DataReader
Now will import pinkfish as pf work,it give deprecated Waring,but that can just ignore.

I have another issue with the pinkish package
the full code is here:
full code
when get to this line:
elif (tlog.num_open_trades() == 0
          and row.sma50 > row.sma200 and ts['sma50'][i-1] <= ts['sma200'][i-1]):
Error:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-30-56c406d527ea> in <module> 10 shares = tlog.exit_trade(date, close) 11 # buy ---> 12 elif (tlog.num_open_trades() == 0 13 and row.macd_fast > row.macd_slow and data['diff fast'][i-1] <= data['slow singal'][i-1]): 14 D:\programs\anaconda3\lib\site-packages\pinkfish\trade.py in num_open_trades(self) 54 def num_open_trades(self): 55 """ return number of open orders, i.e. not closed out """ ---> 56 return len(self._get_open_trades()) 57 58 def exit_trade(self, exit_date, exit_price, shares=-1, long_short='long'): D:\programs\anaconda3\lib\site-packages\pinkfish\trade.py in _get_open_trades(self) 50 def _get_open_trades(self): 51 """ find the "integer" index of rows with NaN """ ---> 52 return pd.isnull(self._tlog).any(1).nonzero()[0] 53 54 def num_open_trades(self): D:\programs\anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 5272 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5273 return self[name] -> 5274 return object.__getattribute__(self, name) 5275 5276 def __setattr__(self, name: str, value) -> None: AttributeError: 'Series' object has no attribute 'nonzero'
I know I need to do something with
D:\programs\anaconda3\lib\site-packages\pinkfish\trade.py
return pd.isnull(self._tlog).any(1).nonzero()[0]
and
D:\programs\anaconda3\lib\site-packages\pandas\core\generic.py
return object.__getattribute__(self, name)

I google searched, but cannot seem to find an answer to my specific question.
Reply
#6
Try.
#return pd.isnull(self._tlog).any(1).nonzero()[0]
return pd.isnull(self._tlog).any(1).to_numpy().nonzero()[0]
A other option had to been running in a virtual environment.
Then clone Repo and install requirements.txt
git clone https://github.com/fja05680/pinkfish.git
pip install -r requirements.txt 
Now will running with versions that was used when this was made.
Reply
#7
(May-15-2020, 10:04 PM)snippsat Wrote: Try.
#return pd.isnull(self._tlog).any(1).nonzero()[0]
return pd.isnull(self._tlog).any(1).to_numpy().nonzero()[0]
A other option had to been running in a virtual environment.
Then clone Repo and install requirements.txt
git clone https://github.com/fja05680/pinkfish.git
pip install -r requirements.txt 
Now will running with versions that was used when this was made.


Thank you very much for your time.
I tried
return pd.isnull(self._tlog).any(1).to_numpy().nonzero()[0]
still have error message
Error:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-81-56c406d527ea> in <module> 10 shares = tlog.exit_trade(date, close) 11 # buy ---> 12 elif (tlog.num_open_trades() == 0 13 and row.macd_fast > row.macd_slow and data['diff fast'][i-1] <= data['slow singal'][i-1]): 14 D:\programs\anaconda3\lib\site-packages\pinkfish\trade.py in num_open_trades(self) 54 def num_open_trades(self): 55 """ return number of open orders, i.e. not closed out """ ---> 56 return len(self._get_open_trades()) 57 58 def exit_trade(self, exit_date, exit_price, shares=-1, long_short='long'): D:\programs\anaconda3\lib\site-packages\pinkfish\trade.py in _get_open_trades(self) 50 def _get_open_trades(self): 51 """ find the "integer" index of rows with NaN """ ---> 52 return pd.isnull(self._tlog).any(1).to_numpy().nonzero()[0] 53 54 def num_open_trades(self): D:\programs\anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 5272 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5273 return self[name] -> 5274 return object.__getattribute__(self, name) 5275 5276 def __setattr__(self, name: str, value) -> None: AttributeError: 'Series' object has no attribute 'nonzero'
I tried nonempty to replace nonzero still not working.

I also tried to downgrade the pandas to 0.24.2. then I ran into so many other error codes on my existing code.
so a downgrade pandas is not a good option I think.

I was reading at pandas.pydata.org, didn't see much info regarding to_numpy().nonzero()[0]

is there any alternative ?
Reply
#8
(May-16-2020, 04:48 PM)buunaanaa Wrote: Is there any alternative ?
Yes there is,so this a Notebook i run as test.
As you see no errors.

Some step this will create a virtual environment with conda .
I use cmder but commands are just the same in cmd.
You may need to install git
# Make
G:\Anaconda3\Scripts
λ conda create --name pink_env

# Activate
G:\Anaconda3\Scripts
λ activate pink_env

# Cd to pink
(pink_env) G:\Anaconda3\Scripts
λ cd ..

(pink_env) G:\Anaconda3
λ cd envs\pink_env\

(pink_env) G:\Anaconda3
λ cd envs\pink_env\

# Clone Repo
(pink_env) G:\Anaconda3\envs\pink_env
λ git clone https://github.com/fja05680/pinkfish.git

# Remove these 3 from requirements.txt save as req.txt
importlib-metadata==0.18
empyrical==0.5.3
TA-Lib==0.4.17

# Install req.txt
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ conda install --file req.txt

# new file req1.txt
importlib-metadata==0.18
empyrical==0.5.3

# Install req1.txt with pip
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ pip install -r req1.txt

# Install NoteBook
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ conda install -c conda-forge jupyterlab
From gohlke download TA_Lib‑0.4.18‑cp37‑cp37m‑win_amd64.whl
# Install
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ pip install TA_Lib-0.4.18-cp37-cp37m-win_amd64.whl
Processing g:\anaconda3\envs\pink_env\pinkfish\ta_lib-0.4.18-cp37-cp37m-win_amd64.whl
Installing collected packages: TA-Lib
Successfully installed TA-Lib-0.4.18
Finish Pray
# Start Jupyterlab
(pink_env) G:\Anaconda3\envs\pink_env\pinkfish (master)
λ jupyter lab
Reply
#9
(May-15-2020, 10:04 PM)snippsat Wrote: Try.
#return pd.isnull(self._tlog).any(1).nonzero()[0]
return pd.isnull(self._tlog).any(1).to_numpy().nonzero()[0]
A other option had to been running in a virtual environment.
Then clone Repo and install requirements.txt
git clone https://github.com/fja05680/pinkfish.git
pip install -r requirements.txt 
Now will running with versions that was used when this was made.

you have been amazing. I feel bad I am new and getting so many issues.
after I ran
[/python]
install requirements.txt
[/python]

Here is the requirement file.
[inline]appdirs==1.4.3
astroid==2.2.5
atomicwrites==1.3.0
attrs==19.1.0
certifi==2019.6.16
chardet==3.0.4
Click==7.0
colorama==0.4.1
configparser==3.7.4
coverage==4.5.3
cycler==0.10.0
empyrical==0.5.3
idna==2.8
importlib-metadata==0.18
ipython==7.11.1
isort==4.3.20
kiwisolver==1.1.0
lazy-object-proxy==1.4.1
lxml==4.3.4
matplotlib==3.1.0
mccabe==0.6.1
more-itertools==7.0.0
numpy==1.16.4
packaging==19.0
pandas==0.24.2
pandas-datareader==0.7.0
pluggy==0.12.0
py==1.8.0
pylint==2.3.1
pyparsing==2.4.0
pytest==4.6.3
pytest-cov==2.7.1
pytest-mock==1.10.4
python-dateutil==2.8.0
pytz==2019.1
requests==2.22.0
six==1.12.0
TA-Lib==0.4.17
toml==0.10.0
typed-ast==1.4.0
urllib3==1.25.3
wcwidth==0.1.7
wrapt==1.11.2
zipp==0.5.1[/inline]

I found out pandas 0.24.2 won't solve the issue,
I uninstalled the panda 0.24.2 and installed panda 1.0.3

suppose to work now but keep running into issues.
i had bottleneck issue. it was solved after i installed the bottleneck package. etc...

until i ran into a new error,

Error:
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-2-85928ad91014> in <module> ----> 1 import pandas as pd 2 import numpy as np 3 import os 4 5 from pandas import DataFrame D:\programs\anaconda3\lib\site-packages\pandas\__init__.py in <module> 53 import pandas.core.config_init 54 ---> 55 from pandas.core.api import ( 56 # dtype 57 Int8Dtype, D:\programs\anaconda3\lib\site-packages\pandas\core\api.py in <module> 1 # flake8: noqa 2 ----> 3 from pandas._libs import NaT, Period, Timedelta, Timestamp 4 from pandas._libs.missing import NA 5 ImportError: cannot import name 'NaT' from 'pandas._libs' (unknown location)
some people suggest to uninstall pandas and reinstall it and it solved the issue. but mine didn't solve the issue...
is there a way to restore to my original built before I ran the requirement when everything was working?
Reply
#10
You are running on the main installation and not in a virtual environment.
Quote:I found out pandas 0.24.2 won't solve the issue,
I uninstalled the panda 0.24.2 and installed panda 1.0.3
All version will not match if not run i a virtual environment with version in requirements.txt.

If mess up now it may not be so easy to fix at all,may be better to start on a new Anaconda installation or lighter Miniconda .
Can try to see if conda can fix it,you most also look into what conda dos as it a very important part of Anaconda.
pip uninstall pandas 
conda update pandas
If mess up in virtual environment as did one time testing this it dos not matter at all as can just delete the pink_env folder an start a new environment.

Pinkfish all sudo install Doh
Had not look at install instruction which i don't like,it'only for Linux so it dos not matter.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020