Skip to content

Commit

Permalink
Merge 5e9c85c into d57b41a
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Sanderson committed Mar 31, 2020
2 parents d57b41a + 5e9c85c commit 2456171
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 94 deletions.
6 changes: 1 addition & 5 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ install:
# https://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/ for 64bit C compilation
- ps: copy .\ci\appveyor\vcvars64.bat "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64"
- "ECHO APPVEYOR_PULL_REQUEST_NUMBER is: %APPVEYOR_PULL_REQUEST_NUMBER%"
- "%CMD_IN_ENV% python .\\ci\\make_conda_packages.py"

# test that we can conda install zipline in a new env
- conda create -n installenv --yes -q --use-local python=%PYTHON_VERSION% numpy=%NUMPY_VERSION% zipline -c quantopian -c https://conda.anaconda.org/quantopian/label/ci

- ps: $env:BCOLZ_VERSION=(sls "bcolz==([^ ]*)" .\etc\requirements_locked.txt -ca).matches.groups[1].value
- ps: $env:NUMEXPR_VERSION=(sls "numexpr==([^ ]*)" .\etc\requirements_locked.txt -ca).matches.groups[1].value
Expand All @@ -106,7 +102,7 @@ install:
# Since conda installs latest certifi by default, we would fail to uninstall that new version when trying to install the pinned version using pip later in the build:
# "Cannot uninstall 'certifi'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall."
- ps: $env:CERTIFI_VERSION=(sls "certifi==([^ ]*)" .\etc\requirements_locked.txt -ca).matches.groups[1].value
- conda create -n testenv --yes -q --use-local "pip<19" python=%PYTHON_VERSION% numpy=%NUMPY_VERSION% pandas=%PANDAS_VERSION% scipy=%SCIPY_VERSION% ta-lib=%TALIB_VERSION% bcolz=%BCOLZ_VERSION% numexpr=%NUMEXPR_VERSION% pytables=%PYTABLES_VERSION% h5py=%H5PY_VERSION% certifi=%CERTIFI_VERSION% -c quantopian -c https://conda.anaconda.org/quantopian/label/ci
- conda create -n testenv --yes -q --use-local "pip<19" python=%PYTHON_VERSION% numpy=%NUMPY_VERSION% pandas=%PANDAS_VERSION% scipy=%SCIPY_VERSION% ta-lib=%TALIB_VERSION% bcolz=%BCOLZ_VERSION% numexpr=%NUMEXPR_VERSION% pytables=%PYTABLES_VERSION% h5py=%H5PY_VERSION% certifi=%CERTIFI_VERSION% -c quantopian -c https://conda.anaconda.org/quantopian/label/ci -c conda-forge
- activate testenv
- bash etc/dev-install --cache-dir=%LOCALAPPDATA%\pip\Cache\pip_np%CONDA_NPY%py%CONDA_PY%
- python -m pip freeze | sort
Expand Down
8 changes: 0 additions & 8 deletions conda/logbook/bld.bat

This file was deleted.

9 changes: 0 additions & 9 deletions conda/logbook/build.sh

This file was deleted.

61 changes: 0 additions & 61 deletions conda/logbook/meta.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion etc/dev-install
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ echo

# New releases of pip have frequently caused strange issues. Make sure
# we know exactly which version we're working with.
python -m pip install pip==19.2.2 $@
python -m pip install pip==19.2.2 'setuptools<46' $@

# Install external requirements first: if they share any of our
# transitive dependencies, we want our pinned versions to win.
Expand Down
34 changes: 26 additions & 8 deletions tests/pipeline/test_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,9 @@ class C(Classifier):

@parameter_space(
dtype_and_missing=[(int64_dtype, -1), (categorical_dtype, None)],
use_mask=[True, False],
)
def test_peer_count(self, dtype_and_missing):
def test_peer_count(self, dtype_and_missing, use_mask):
class C(Classifier):
dtype = dtype_and_missing[0]
missing_value = dtype_and_missing[1]
Expand All @@ -636,12 +637,29 @@ class C(Classifier):
missing_value=None,
)

expected = np.array(
[[3, 3, np.nan, 1, 3, np.nan],
[4, 1, 1, 4, 4, 4],
[np.nan, 1, 3, 3, 3, np.nan],
[6, 6, 6, 6, 6, 6]],
)
if not use_mask:
mask = self.build_mask(self.ones_mask(shape=data.shape))
expected = np.array(
[[3, 3, np.nan, 1, 3, np.nan],
[4, 1, 1, 4, 4, 4],
[np.nan, 1, 3, 3, 3, np.nan],
[6, 6, 6, 6, 6, 6]],
)
else:
# Punch a couple holes in the mask to check that we handle the mask
# correctly.
mask = self.build_mask(
np.array([[1, 1, 1, 1, 0, 1],
[1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1],
[1, 1, 0, 0, 1, 1]], dtype='bool')
)
expected = np.array(
[[2, 2, np.nan, 1, np.nan, np.nan],
[3, 1, 1, 3, 3, np.nan],
[np.nan, 1, 3, 3, 3, np.nan],
[4, 4, np.nan, np.nan, 4, 4]],
)

terms = {
'peer_counts': c.peer_count(),
Expand All @@ -654,7 +672,7 @@ class C(Classifier):
terms=terms,
expected=expected_results,
initial_workspace={c: data},
mask=self.build_mask(self.ones_mask(shape=data.shape)),
mask=mask,
)


Expand Down
10 changes: 8 additions & 2 deletions zipline/pipeline/classifiers/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,17 @@ def _to_integral(self, output_array):
)
return group_labels, null_label

def peer_count(self):
def peer_count(self, mask=NotSpecified):
"""
Construct a factor that gives the number of occurrences of
each distinct category in a classifier.
Parameters
----------
mask : zipline.pipeline.Filter, optional
If passed, only count assets passing the filter. Default behavior
is to count all assets.
Examples
--------
Let ``c`` be a Classifier which would produce the following output::
Expand Down Expand Up @@ -433,7 +439,7 @@ def peer_count(self):
"""
# Lazy import due to cyclic dependencies in factor.py, classifier.py
from ..factors import PeerCount
return PeerCount(inputs=[self])
return PeerCount(inputs=[self], mask=mask)


class Everything(Classifier):
Expand Down

0 comments on commit 2456171

Please sign in to comment.