# Brian2.test() reports a TypeError in test\_numpy\_functions\_logical

**URL:** https://brian.discourse.group/t/brian2-test-reports-a-typeerror-in-test-numpy-functions-logical/460
**Category:** Support
**Created:** [20 August 2021 13:47 UTC](https://brian.discourse.group/t/brian2-test-reports-a-typeerror-in-test-numpy-functions-logical/460 "2021-08-20T13:47:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![moritz](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/moritz/32/239_2.png) [@moritz](https://brian.discourse.group/u/moritz)
#### Post date: [20 August 2021 13:47 UTC](https://brian.discourse.group/t/brian2-test-reports-a-typeerror-in-test-numpy-functions-logical/460/1 "2021-08-20T13:47:09Z")

</div>

# Description of problem

brian2.test() reports:  
TypeError: logical\_and() takes from 2 to 3 positional arguments but 1 were given

```
FAILED ../../../../../../opt/anaconda/envs/TheBrianBlank/lib/python3.9/site-packages/brian2/tests/test_units.py::test_numpy_functions_logical

```

# Minimal code to reproduce problem

import brian2  
brian2.test()

# What you have aready tried

I first got the error in a pip managed environment (no anaconda).  
I installed anaconda and set up a new environment. I followed the installation guide  
conda config --add channels conda-forge  
conda install matplotlib pytest ipython notebook brian2 sphinx doctest

But i still get the same error

# Expected output

OK

# Actual output

False

# Full traceback of error

Running tests in /opt/anaconda/envs/TheBrianBlank/lib/python3.9/site-packages/brian2 for targets numpy, cython (excluding long tests)  
Running Brian version 2.4.2 from ‘/opt/anaconda/envs/TheBrianBlank/lib/python3.9/site-packages/brian2’  
Testing codegen-independent code  
Resetting to default preferences

Running doctests  
… [100%]  
=============================== warnings summary ===============================  
core/operations.py::brian2.core.operations.network\_operation  
/opt/anaconda/envs/TheBrianBlank/lib/python3.9/site-packages/brian2/core/clocks.py:95: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.  
Deprecated in NumPy 1.20; for more details and guidance: (link removed)  
dtype=np.float, read\_only=True, constant=True,

monitors/spikemonitor.py::brian2.monitors.spikemonitor.EventMonitor.all\_values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.EventMonitor.values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.SpikeMonitor  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.SpikeMonitor.all\_values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.SpikeMonitor.values  
/opt/anaconda/envs/TheBrianBlank/lib/python3.9/site-packages/brian2/groups/neurongroup.py:313: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.  
Deprecated in NumPy 1.20; for more details and guidance: (link removed)  
self.variables.add\_auxiliary\_variable(‘\_cond’, dtype=np.bool)

monitors/spikemonitor.py::brian2.monitors.spikemonitor.EventMonitor.all\_values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.EventMonitor.all\_values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.EventMonitor.values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.SpikeMonitor.all\_values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.SpikeMonitor.all\_values  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.SpikeMonitor.spike\_trains  
monitors/spikemonitor.py::brian2.monitors.spikemonitor.SpikeMonitor.values  
/opt/anaconda/envs/TheBrianBlank/lib/python3.9/site-packages/brian2/groups/group.py:257: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.  
Deprecated in NumPy 1.20; for more details and guidance: (link removed)  
if index\_array.dtype == np.bool:

– Docs: (link removed)  
41 passed, 13 warnings in 7.26s  
Running tests that do not use code generation  
…

WARNING The expression “i1 / 1” divides two integer values. In previous versions of Brian, this would have used either an integer (“flooring”) or a floating point division, depending on the Python version and the code generation target. In the current version, it always uses a floating point division. Explicitly ask for an integer division (“//”), or turn one of the operands into a floating point value (e.g. replace “1/2” by “1.0/2”) to no longer receive this warning. [brian2.parsing.bast.floating\_point\_division]

… [19%]  
… [39%]  
…

WARNING The expression “(i + 1) / N” divides two integer values. In previous versions of Brian, this would have used either an integer (“flooring”) or a floating point division, depending on the Python version and the code generation target. In the current version, it always uses a floating point division. Explicitly ask for an integer division (“//”), or turn one of the operands into a floating point value (e.g. replace “1/2” by “1.0/2”) to no longer receive this warning. [brian2.parsing.bast.floating\_point\_division]

…ss… [59%]  
…

WARNING The ‘independent’ state updater is deprecated and might be removed in future versions of Brian. [brian2.stateupdaters.exact.deprecated\_independent]

.. [79%]  
…F… [99%]  
.. [100%]  
=================================== FAILURES ===================================  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ test\_numpy\_functions\_logical \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

```
@pytest.mark.codegen_independent
def test_numpy_functions_logical():
    '''
    Assure that logical numpy functions work on all quantities and return
    unitless boolean arrays.
    '''
    unit_values1 = [3 * mV, np.array([1, 2]) * mV, np.ones((3, 3)) * mV]
    unit_values2 = [3 * second, np.array([1, 2]) * second,
                    np.ones((3, 3)) * second]
    for ufunc in UFUNCS_LOGICAL:
        for value1, value2 in zip(unit_values1, unit_values2):
            try:
                # one argument

```

> ```
> result_units = eval('np.%s(value1)' % ufunc)
> 
> ```

/opt/anaconda/envs/TheBrianBlank/lib/python3.9/site-packages/brian2/tests/test\_units.py:976:

* * *

> ???  
> E TypeError: logical\_and() takes from 2 to 3 positional arguments but 1 were given

:1: TypeError

… Output continues but the rest is Ok. (I had to remove the links in the output since i am a new user)

---

<div class="post-metadata">

### Author: ![moritz](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/moritz/32/239_2.png) [@moritz](https://brian.discourse.group/u/moritz)
#### Post date: [23 August 2021 10:53 UTC](https://brian.discourse.group/t/brian2-test-reports-a-typeerror-in-test-numpy-functions-logical/460/2 "2021-08-23T10:53:02Z")

</div>

Seems like the functions logical\_and, logical\_or and logical\_xor raise a TypeError in case there is a missing argument:

```auto
for ufunc in UFUNCS_LOGICAL:
    for value1, value2 in zip(unit_values1, unit_values2):
        try:
            # one argument
            result_units = eval('np.%s(value1)' % ufunc)        
            result_array = eval('np.%s(np.array(value1))' % ufunc)
        except (ValueError, TypeError) as e:
            print(ufunc, type(e))

```

OUTPUT:

logical\_and \<class ‘TypeError’\>  
logical\_and \<class ‘TypeError’\>  
logical\_and \<class ‘TypeError’\>  
logical\_or \<class ‘TypeError’\>  
logical\_or \<class ‘TypeError’\>  
logical\_or \<class ‘TypeError’\>  
logical\_xor \<class ‘TypeError’\>  
logical\_xor \<class ‘TypeError’\>  
logical\_xor \<class ‘TypeError’\>

I replaced line 978 in test\_units.py  
` except ValueError:`  
with:  
` except TypeError:`

This fixes the bug for me. Is this a general thing ?  
(My package versions are numpy 1.21.2 and brian2 2.4.2)

best,  
Moritz

---

<div class="post-metadata">

### Author: ![denisalevi](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/denisalevi/32/24_2.png) [@denisalevi](https://brian.discourse.group/u/denisalevi)
#### Post date: [23 August 2021 14:17 UTC](https://brian.discourse.group/t/brian2-test-reports-a-typeerror-in-test-numpy-functions-logical/460/3 "2021-08-23T14:17:10Z")

</div>

Hi @moritz,

the test has already been fixed [here in brian2](https://github.com/brian-team/brian2/commit/62fa44914390f4c85d0ec2e7027aee95436fe6d3) master and should pass in the next release. It seems the latest numpy version has changed the error type raised here. I think you can safely ignore the failed test.

Best,  
Denis

---

<div class="post-metadata">

### Author: ![moritz](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/moritz/32/239_2.png) [@moritz](https://brian.discourse.group/u/moritz)
#### Post date: [23 August 2021 14:21 UTC](https://brian.discourse.group/t/brian2-test-reports-a-typeerror-in-test-numpy-functions-logical/460/4 "2021-08-23T14:21:58Z")

</div>

Perfect, Thank you!

best,  
Moritz
