Skip to content

Commit

Permalink
MAINT: Fix warnings and codecov (stefan-jansen#145)
Browse files Browse the repository at this point in the history
* Int64Index to Index(..., dtype=..)
* group_keys to False
* add codecov token
  • Loading branch information
stefan-jansen authored Nov 4, 2022
1 parent 2e29aed commit 33bec86
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 42 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci_tests_quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
name: codecov-umbrella
verbose: true
6 changes: 4 additions & 2 deletions src/zipline/assets/asset_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def check_intersections(persymbol):
msg_component = "\n ".join(str(data).splitlines())
ambiguous[persymbol.name] = intersections, msg_component

mappings.groupby(["symbol", "country_code"]).apply(check_intersections)
mappings.groupby(["symbol", "country_code"], group_keys=False).apply(
check_intersections
)

if ambiguous:
raise ValueError(
Expand Down Expand Up @@ -378,7 +380,7 @@ def _split_symbol_mappings(df, exchanges):

_check_symbol_mappings(mappings, exchanges, asset_exchange)
return (
df.groupby(level=0).apply(_check_asset_group),
df.groupby(level=0, group_keys=False).apply(_check_asset_group),
mappings,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ def test_drawdown(self):
class ParameterizedFactorTestCase(
zf.WithAssetFinder, zf.WithTradingCalendars, zf.ZiplineTestCase
):
sids = ASSET_FINDER_EQUITY_SIDS = pd.Int64Index([1, 2, 3])
sids = ASSET_FINDER_EQUITY_SIDS = pd.Index([1, 2, 3], dtype="int64")
START_DATE = pd.Timestamp("2015-01-31", tz="UTC")
END_DATE = pd.Timestamp("2015-03-01", tz="UTC")
ASSET_FINDER_COUNTRY_CODE = "??"
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/test_frameload.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def frame_loader(request):
request.cls.trading_day = get_calendar("NYSE").day
request.cls.nsids = 5
request.cls.ndates = 20
request.cls.sids = pd.Int64Index(range(request.cls.nsids))
request.cls.sids = pd.Index(range(request.cls.nsids), dtype="int64")
request.cls.dates = pd.date_range(
start="2014-01-02",
freq=request.cls.trading_day,
Expand Down
22 changes: 11 additions & 11 deletions tests/pipeline/test_numerical_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DateFactor(Factor):
@pytest.fixture(scope="function")
def set_num_expression(request):
request.cls.dates = pd.date_range("2014-01-01", periods=5, freq="D")
request.cls.assets = pd.Int64Index(range(5))
request.cls.assets = pd.Index(range(5), dtype="int64")
request.cls.f = F()
request.cls.g = G()
request.cls.h = H()
Expand Down Expand Up @@ -394,20 +394,20 @@ def test_divide(self):
def test_pow(self):
f, g = self.f, self.g

self.check_constant_output(f ** g, 3.0 ** 2)
self.check_constant_output(2 ** f, 2.0 ** 3)
self.check_constant_output(f ** 2, 3.0 ** 2)
self.check_constant_output(f**g, 3.0**2)
self.check_constant_output(2**f, 2.0**3)
self.check_constant_output(f**2, 3.0**2)

self.check_constant_output((f + g) ** 2, (3.0 + 2.0) ** 2)
self.check_constant_output(2 ** (f + g), 2 ** (3.0 + 2.0))

self.check_constant_output(f ** (f ** g), 3.0 ** (3.0 ** 2.0))
self.check_constant_output((f ** f) ** g, (3.0 ** 3.0) ** 2.0)
self.check_constant_output(f ** (f**g), 3.0 ** (3.0**2.0))
self.check_constant_output((f**f) ** g, (3.0**3.0) ** 2.0)

self.check_constant_output((f ** g) ** (f ** g), 9.0 ** 9.0)
self.check_constant_output((f ** g) ** (g ** f), 9.0 ** 8.0)
self.check_constant_output((g ** f) ** (f ** g), 8.0 ** 9.0)
self.check_constant_output((g ** f) ** (g ** f), 8.0 ** 8.0)
self.check_constant_output((f**g) ** (f**g), 9.0**9.0)
self.check_constant_output((f**g) ** (g**f), 9.0**8.0)
self.check_constant_output((g**f) ** (f**g), 8.0**9.0)
self.check_constant_output((g**f) ** (g**f), 8.0**8.0)

def test_mod(self):
f, g = self.f, self.g
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_comparisons(self):
(f + 1, g, f_data + 1, g_data),
(f, g + 1, f_data, g_data + 1),
(f + 1, g + 1, f_data + 1, g_data + 1),
((f + g) / 2, f ** 2, (f_data + g_data) / 2, f_data ** 2),
((f + g) / 2, f**2, (f_data + g_data) / 2, f_data**2),
]
for op in (gt, ge, lt, le, ne):
for expr_lhs, expr_rhs, expected_lhs, expected_rhs in cases:
Expand Down
4 changes: 2 additions & 2 deletions tests/pipeline/test_statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
class StatisticalBuiltInsTestCase(
zf.WithAssetFinder, zf.WithTradingCalendars, zf.ZiplineTestCase
):
sids = ASSET_FINDER_EQUITY_SIDS = pd.Int64Index([1, 2, 3])
sids = ASSET_FINDER_EQUITY_SIDS = pd.Index([1, 2, 3], dtype="int64")
START_DATE = pd.Timestamp("2015-01-31", tz="UTC")
END_DATE = pd.Timestamp("2015-03-01", tz="UTC")
ASSET_FINDER_EQUITY_SYMBOLS = ("A", "B", "C")
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_simple_beta_graph_repr(self):


class StatisticalMethodsTestCase(zf.WithSeededRandomPipelineEngine, zf.ZiplineTestCase):
sids = ASSET_FINDER_EQUITY_SIDS = pd.Int64Index([1, 2, 3])
sids = ASSET_FINDER_EQUITY_SIDS = pd.Index([1, 2, 3], dtype="int64")
START_DATE = pd.Timestamp("2015-01-31", tz="UTC")
END_DATE = pd.Timestamp("2015-03-01", tz="UTC")
ASSET_FINDER_COUNTRY_CODE = "US"
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/test_us_equity_pricing_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_read_with_adjustments(self):
domain=US_EQUITIES,
columns=columns,
dates=query_days,
sids=pd.Int64Index(np.arange(1, 7)),
sids=pd.Index(np.arange(1, 7), dtype="int64"),
mask=np.ones((len(query_days), 6), dtype=bool),
)
highs, volumes = map(getitem(results), columns)
Expand Down
45 changes: 22 additions & 23 deletions tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@
"""
Tests for the zipline.assets package
"""
from collections import namedtuple
from datetime import timedelta
from functools import partial
import os
import pickle
import re
import string
import sys
from types import GetSetDescriptorType
import uuid
from collections import namedtuple
from datetime import timedelta
from functools import partial
from types import GetSetDescriptorType

from parameterized import parameterized
import numpy as np
import pandas as pd
import pytest
import sqlalchemy as sa
from parameterized import parameterized
from toolz import valmap, concat

from zipline.assets import (
Asset,
Expand All @@ -39,22 +42,20 @@
AssetDBWriter,
AssetFinder,
)
from zipline.assets.assets import OwnershipPeriod
from zipline.assets.synthetic import (
make_commodity_future_info,
make_rotating_equity_info,
make_simple_equity_info,
)
from toolz import valmap, concat

from zipline.assets.asset_db_migrations import downgrade
from zipline.assets.asset_db_schema import ASSET_DB_VERSION
from zipline.assets.asset_writer import (
check_version_info,
write_version_info,
_futures_defaults,
SQLITE_MAX_VARIABLE_NUMBER,
)
from zipline.assets.asset_db_schema import ASSET_DB_VERSION
from zipline.assets.asset_db_migrations import downgrade
from zipline.assets.assets import OwnershipPeriod
from zipline.assets.synthetic import (
make_commodity_future_info,
make_rotating_equity_info,
make_simple_equity_info,
)
from zipline.errors import (
EquitiesNotFound,
FutureContractsNotFound,
Expand All @@ -78,15 +79,12 @@
tmp_assets_db,
tmp_asset_finder,
)

from zipline.testing.predicates import assert_index_equal, assert_frame_equal
from zipline.testing.fixtures import (
WithAssetFinder,
ZiplineTestCase,
WithTradingCalendars,
)
import pytest
import re
from zipline.testing.predicates import assert_index_equal, assert_frame_equal

Case = namedtuple("Case", "finder inputs as_of country_code expected")

Expand Down Expand Up @@ -1086,13 +1084,14 @@ def test_compute_lifetimes(self):
expected_no_start_raw[i, j] = True

for country_codes in powerset(exchanges.country_code.unique()):
expected_sids = pd.Int64Index(
expected_sids = pd.Index(
sorted(
concat(
sids_by_country[country_code]
for country_code in country_codes
)
)
),
dtype="int64",
)
permuted_sids = [sid for sid in sorted(expected_sids, key=permute_sid)]
tile_count = len(country_codes) + ("US" in country_codes)
Expand All @@ -1102,7 +1101,7 @@ def test_compute_lifetimes(self):
tile_count,
),
index=dates,
columns=pd.Int64Index(permuted_sids),
columns=pd.Index(permuted_sids, dtype="int64"),
)
result = finder.lifetimes(
dates,
Expand All @@ -1119,7 +1118,7 @@ def test_compute_lifetimes(self):
tile_count,
),
index=dates,
columns=pd.Int64Index(permuted_sids),
columns=pd.Index(permuted_sids, dtype="int64"),
)
result = finder.lifetimes(
dates,
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_pandas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_categorical_df_concat(self):
),
},
)
expected.index = pd.Int64Index([0, 1, 2, 0, 1, 2, 0, 1, 2])
expected.index = pd.Index([0, 1, 2, 0, 1, 2, 0, 1, 2], dtype="int64")
assert_equal(expected, result)
assert_equal(expected["A"].cat.categories, result["A"].cat.categories)
assert_equal(expected["C"].cat.categories, result["C"].cat.categories)
Expand Down

0 comments on commit 33bec86

Please sign in to comment.