[Python-announce] unittest_expander 0.4.3 released

2023-03-20 Thread Jan Kaliszewski
I am pleased to announce the release of unittest_expander 0.4.3.

The changelog is available at:
https://unittest-expander.readthedocs.io/en/stable/changes.html

*unittest_expander* is a MIT-licensed Python library that provides
flexible and easy-to-use tools to parameterize your unit tests,
especially those based on `unittest.TestCase`.

The library is compatible with Python 3.11, 3.10, 3.9, 3.8, 3.7, 3.6 and
2.7, and does not depend on any external packages (uses only the Python
standard library).

Simple usage example:

```
import unittest
from unittest_expander import expand, foreach, param

@expand
class TestSomething(unittest.TestCase):
@foreach(
'Foo',
('Foo', 43),
param('Foo', spam=44),
param(foo='Bar', spam=45).label('with bar'),
empty=param(foo='', spam=46),
)
def test_it(self, foo, spam=42, label=None):
assert foo in ('Foo', 'Bar', '')
assert 42 <= spam <= 46
if label == 'with bar':
assert foo == 'Bar' and spam == 45
if label == 'empty':
assert foo == '' and spam == 46
```

This is only a fraction of the possibilities the unittest_expander
library provides.

Homepage: https://github.com/zuo/unittest_expander
PyPI: https://pypi.org/project/unittest-expander/
Documentation: https://unittest-expander.readthedocs.io/en/stable/

Cheers,
Jan Kaliszewski (zuo) 
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


Re: Debugging reason for python running unreasonably slow when adding numbers

2023-03-20 Thread Thomas Passin

On 3/20/2023 11:21 AM, Edmondo Giovannozzi wrote:



def sum1():
 s = 0
 for i in range(100):
 s += i
 return s

def sum2():
 return sum(range(100))

Here you already have the numbers you want to add.


Actually using numpy you'll be much faster in this case:

§ import numpy as np
§ def sum3():
§return np.arange(1_000_000, dtype=np.int64).sum()

On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms
One problem is that sum2 gives the wrong result. This is why I used np.arange 
with dtype=np.int64.


On my computer they all give the same result.

Python 3.10.9, PyQt version 6.4.1
Windows 10 AMD64 (build 10.0.19044) SP0
Processor: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, 1690 Mhz, 4 
Core(s), 8 Logical Processor(s)




sum2 evidently doesn't uses the python "big integers" e restrict the result to 
32 bits.


What about your system?  Let's see if we can figure the reason for the 
difference.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Debugging reason for python running unreasonably slow when adding numbers

2023-03-20 Thread MRAB

On 2023-03-20 15:21, Edmondo Giovannozzi wrote:


> def sum1(): 
> s = 0 
> for i in range(100): 
> s += i 
> return s 
> 
> def sum2(): 
> return sum(range(100))
Here you already have the numbers you want to add. 


Actually using numpy you'll be much faster in this case:

§ import numpy as np
§ def sum3():
§return np.arange(1_000_000, dtype=np.int64).sum()

On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms
One problem is that sum2 gives the wrong result. This is why I used np.arange 
with dtype=np.int64.

sum2 evidently doesn't uses the python "big integers" e restrict the result to 
32 bits.


On my computer they all give the same result, as I'd expect.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Debugging reason for python running unreasonably slow when adding numbers

2023-03-20 Thread Edmondo Giovannozzi

> > def sum1(): 
> > s = 0 
> > for i in range(100): 
> > s += i 
> > return s 
> > 
> > def sum2(): 
> > return sum(range(100))
> Here you already have the numbers you want to add. 

Actually using numpy you'll be much faster in this case:

§ import numpy as np
§ def sum3():
§return np.arange(1_000_000, dtype=np.int64).sum()

On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms
One problem is that sum2 gives the wrong result. This is why I used np.arange 
with dtype=np.int64.

sum2 evidently doesn't uses the python "big integers" e restrict the result to 
32 bits.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get get_body() to work? (about email)

2023-03-20 Thread Jon Ribbens via Python-list
On 2023-03-19, Greg Ewing  wrote:
> On 20/03/23 7:07 am, Jon Ribbens wrote:
>> Ah, apparently it got removed in Python 3, which is a bit odd as the
>> last I heard it was added in Python 2.2 in order to achieve consistency
>> with other types.
>
> As far as I remember, the file type came into existence
> with type/class unification, and "open" became an alias
> for the file type, so you could use open() and file()
> interchangeably.
>
> With the Unicode revolution in Python 3, file handling got
> a lot more complicated. Rather than a single file type,
> there are now a bunch of classes that handle low-level I/O,
> encoding/decoding, etc, and open() is a function again
> that builds the appropriate combination of underlying
> objects.

This is true, however there does exist a base class which, according to
the documentation, underlies all of the different IO classes - IOBase -
so it might have been neater to make 'file' be an alias for that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get get_body() to work? (about email)

2023-03-20 Thread Jon Ribbens via Python-list
On 2023-03-19, Stefan Ram  wrote:
> Jon Ribbens  writes:
>>(Also, I too find it annoying to have to avoid, but calling a local
>>variable 'file' is somewhat suspect since it shadows the builtin.)
>
>   Thanks for your remarks, but I'm not aware
>   of such a predefined name "file"!

Ah, apparently it got removed in Python 3, which is a bit odd as the
last I heard it was added in Python 2.2 in order to achieve consistency
with other types.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get get_body() to work? (about email)

2023-03-20 Thread Jon Ribbens via Python-list
On 2023-03-19, Stefan Ram  wrote:
> Peng Yu  writes:
>>But when I try the following code, get_body() is not found. How to get
>>get_body() to work?
>
>   Did you know that this post of mine here was posted to
>   Usenet with a Python script I wrote?
>
>   That Python script has a function to show the body of
>   a post before posting. The post is contained in a file,
>   so it reads the post from that file.
>
>   I copy it here, maybe it can help some people to see
>   how I do this.
>
> # Python 3.5
>
> import email
>
>   ...
>
> def showbody( file ): # lightly edited for posting on 2023-03-19
> output = ''
> msg = email.message_from_binary_file\
> ( file, policy=email.policy.default )

I wouldn't generally be pedantic about code style, but that's giving me
painful convulsions. Backslashes for line continuations are generally
considered a bad idea (as they mean that any whitespace after the
backslash, which is often invisible, becomes significant). And not
indenting the continuation line(s) is pretty shocking. Writing it as
below is objectively better:

msg = email.message_from_binary_file(
file, policy=email.policy.default )

(Also, I too find it annoying to have to avoid, but calling a local
variable 'file' is somewhat suspect since it shadows the builtin.)
-- 
https://mail.python.org/mailman/listinfo/python-list


[Python-announce] ANN: pvlib-0.9.5 released

2023-03-20 Thread Dr. Mark Alexander Mikofski PhD
Dear Pythonistas and solar power enthusiasts,

The maintainers are happy to announce a new release of pvlib python:
software for simulating performance of photovoltaic solar energy systems.

*v0.9.5 Highlights:*
* The infinite_sheds model now has options to use the hay-davies
transposition model and faster vectorized calculations.
* New models for irradiance decomposition (boland) and relative airmass
(gueymard2003).
* Model extensions for multiple strings in pvlib.snow.loss_townsend and AR
coating in pvlib.iam.physical.
* Updated the parameters database for the ADR inverter model.
* Various other bug fixes and testing updates.

For the full list of what's new, see the documentation:
https://pvlib-python.readthedocs.io/en/stable/whatsnew.html

*Releases are available from PyPI and the conda-forge channel:*
* https://pypi.org/project/pvlib/
* https://anaconda.org/conda-forge/pvlib and
https://anaconda.org/conda-forge/pvlib-python
NOTE: new pvlib releases are no longer uploaded to the "pvlib" conda
channel.  Please install from PyPI or the conda-forge channel instead.

*Read the Documentation:*
* https://pvlib-python.readthedocs.io/en/stable/index.html

*Report issues & contribute:*
* https://github.com/pvlib/pvlib-python

*Community discussion & support:*
* https://groups.google.com/g/pvlib-python
* https://github.com/pvlib/pvlib-python/discussions

*Thank you for using pvlib python!*

-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com