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

TypeError: Passing a bool to header is invalid with Pandas 0.18.1 #45

Open
femtotrader opened this issue Jun 20, 2016 · 3 comments
Open

Comments

@femtotrader
Copy link

$ python qsforex/examples/mac.py
/Users/femto/cache/data/random/GBPUSD_20140101.csv
Traceback (most recent call last):
  File "qsforex/examples/mac.py", line 27, in <module>
    equity=settings.EQUITY
  File "/Users/femto/github/femto/qsforex/backtest/backtest.py", line 29, in __init__
    self.ticker = data_handler(self.pairs, self.events, self.csv_dir)
  File "/Users/femto/github/femto/qsforex/data/price.py", line 107, in __init__
    self.file_dates[self.cur_date_idx]
  File "/Users/femto/github/femto/qsforex/data/price.py", line 144, in _open_convert_csv_files_for_day
    names=("Time", "Ask", "Bid", "AskVolume", "BidVolume")
  File "//anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 562, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "//anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 315, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "//anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 641, in __init__
    self.options, self.engine = self._clean_options(options, engine)
  File "//anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 755, in _clean_options
    _validate_header_arg(options['header'])
  File "//anaconda/lib/python3.5/site-packages/pandas/io/common.py", line 265, in _validate_header_arg
    raise TypeError("Passing a bool to header is invalid. "
TypeError: Passing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column names

According docstring

`````` ?pd.read_csv```

header : int or list of ints, default 'infer'
    Row number(s) to use as the column names, and the start of the data.
    Default behavior is as if set to 0 if no ``names`` passed, otherwise
    ``None``. Explicitly pass ``header=0`` to be able to replace existing
    names. The header can be a list of integers that specify row locations for
    a multi-index on the columns e.g. [0,1,3]. Intervening rows that are not
    specified will be skipped (e.g. 2 in this example is skipped). Note that
    this parameter ignores commented lines and empty lines if
    ``skip_blank_lines=True``, so header=0 denotes the first line of data
    rather than the first line of the file

so in https://github.com/mhallsmoore/qsforex/blob/master/data/price.py#L140

        self.pair_frames[p] = pd.io.parsers.read_csv(
            pair_path, header=True, index_col=0, 
            parse_dates=True, dayfirst=True,
            names=("Time", "Ask", "Bid", "AskVolume", "BidVolume")
        )

should be replaced by

        self.pair_frames[p] = pd.io.parsers.read_csv(
            pair_path, header=0, index_col=0, 
            parse_dates=True, dayfirst=True,
            names=("Time", "Ask", "Bid", "AskVolume", "BidVolume")
        )
@femtotrader
Copy link
Author

There is also a warning

qsforex/data/price.py:147: FutureWarning: sort(....) is deprecated, use sort_index(.....)
  return pd.concat(self.pair_frames.values()).sort().iterrows()

@cassianokc
Copy link

I was getting this same error, femtotrader solution fixed it. Is there a PR with this fix already? I can submit one if needed.

@markr9805
Copy link

I also found that the sort on line 146 does not work with pandas 0.20.1.

return pd.concat(self.pair_frames.values()).sort().iterrows()

should be updated to:

return pd.concat(self.pair_frames.values()).sort_index().iterrows()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants