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

Unit Tests #387

Open
8W9aG opened this issue Nov 29, 2024 · 0 comments
Open

Unit Tests #387

8W9aG opened this issue Nov 29, 2024 · 0 comments

Comments

@8W9aG
Copy link

8W9aG commented Nov 29, 2024

I was attempting to get this library working with the following code:

import os

import pandas as pd
import quantstats as qs

df = pd.DataFrame(data={
    "afl": [0.0, -0.5, 0.5, 0.2, -0.2],
    "nfl": [0.0, 0.5, -0.5, -0.2, -0.2],
}, index=[
    datetime.datetime(year=2020, month=1, day=1),
    datetime.datetime(year=2020, month=1, day=2),
    datetime.datetime(year=2020, month=1, day=3),
    datetime.datetime(year=2020, month=1, day=4),
    datetime.datetime(year=2020, month=1, day=5),
])
df.index = df.index.tz_localize("UTC")
df.index = pd.to_datetime(df.index)

qs.extend_pandas()
qs.reports.html(df, "SPY", output=os.path.join(self._name, "test.html"))

However I receive the issue TypeError: Invalid comparison between dtype=datetime64[ns] and Timestamp with the following traceback:

venv/lib/python3.11/site-packages/quantstats/reports.py:108: in html
    returns, benchmark = _match_dates(returns, benchmark)
venv/lib/python3.11/site-packages/quantstats/reports.py:45: in _match_dates
    loc = max(returns[returns.columns[0]].ne(0).idxmax(), benchmark.ne(0).idxmax())
venv/lib/python3.11/site-packages/pandas/core/ops/common.py:81: in new_method
    return method(self, other)
venv/lib/python3.11/site-packages/pandas/core/arraylike.py:56: in __gt__
    return self._cmp_method(other, operator.gt)
venv/lib/python3.11/site-packages/pandas/core/series.py:6096: in _cmp_method
    res_values = ops.comparison_op(lvalues, rvalues, op)
venv/lib/python3.11/site-packages/pandas/core/ops/array_ops.py:279: in comparison_op
    res_values = op(lvalues, rvalues)
venv/lib/python3.11/site-packages/pandas/core/ops/common.py:81: in new_method
    return method(self, other)
venv/lib/python3.11/site-packages/pandas/core/arraylike.py:56: in __gt__
    return self._cmp_method(other, operator.gt)
venv/lib/python3.11/site-packages/pandas/core/arrays/datetimelike.py:937: in _cmp_method
    return invalid_comparison(self, other, op)

The more I tried to solve this the more indexing issues I ran into, I was wondering if the maintainers would object to me adding some pytest tests to try and wrangle this bug?

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

1 participant