Re: Python Mauritius Usergroup - End of Year report 2020

2021-01-03 Thread Abdur-Rahmaan Janhangeer
Greetings,

^^ Thanks!

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Sun, Jan 3, 2021 at 8:12 AM dn via Python-list 
wrote:

> On 1/3/21 5:01 PM, Abdur-Rahmaan Janhangeer wrote:
> > Greetings list,
> >
> > Here's our usergroup's end of year report for 2020:
> > Happy reading!
> >
> > https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf
>
>
> Well done @A-R!
> --
> Regards =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A random word from one of two lists

2021-01-03 Thread Bischoop
On 2021-01-02, Stefan Ram  wrote:
> Bischoop  writes:
>>On 2021-01-02, Stefan Ram  wrote:
>>>Otherweise, I'd go this way without a dictionary.
>>>import random
>>>animal = ['koala', 'kangaroo']
>>>fruit = ['banana', 'apple']
>>>kinds = [animal,fruit]
>>>kind = random.choice( kinds )
>>>result = random.choice( kind )
>>>print( result )
>>I had that solution in mind but I thought that one is not good
>>programming style or not Pythonin :-)
>
>   I do not see any stylistic problem when you use this approach
>   with "nested lists". List indexing by a number should even be
>   faster than indexing a dictionary.
>
>
Now I know that's ok, seems I was ovethingking while solution was so
simply.

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


Re: Does windows edit .py file shebangs?

2021-01-03 Thread Barry Scott



> On 1 Jan 2021, at 17:03, Eryk Sun  wrote:
> 
> On 1/1/21, Barry Scott  wrote:
>> I found python scripts have had their shebang lines edited behind my back.
>> 
>> The shebang line I'm seeing is:
>> 
>>#!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE
>> 
>> Is this Microsoft being "helpful"?
>> Does anyone know what I will have done to best with this "help"?
>> 
>> What do I need to do to prevent this happening?
> 
> Shebang lines may be localized to the current interpreter when
> installing a package. Otherwise I don't know what's causing that.

These are personal scripts not installed from PyPI for example.

> 
> Regarding Windows, the system doesn't support shebang lines in any
> way. Python's installer associates .py files with the py.exe launcher,
> which looks for a shebang line in a script in order to determine which
> executable to run. It supports shebangs with fully-qualified Windows
> paths, as well as virtual commands for registered installations, such
> as "python", "python3", "python3.9-32", "/usr/bin/python3", and
> "/usr/bin/env python".

Indeed since py.exe is the only tool that supports the shebang this is very 
strange
that the change was made. I rely on py.exe handling shebang for my cross 
platform
scripts.

I've been doing some more investigation and found that the change happened
at 01/01/2021 16:16. The shebang is pointing to a 0 length PYTHON3.EXE.

The files that where changed where all in my %USERPROFILE%\bin
folder that is on my PATH. I manage the files in that folder with tools that
sync the files from an SVN repo. The version of the files in the repo do not
have the edit.

My PATH does not have a PYTHON.EXE or PYTHON3.EXE on it as
I use py.exe.

Is that the path used by the Microsoft store for the python alias?

I have now turned off the alias in the "Manage App execution aliases"
in settings.

I did find this blog post from Steve Dower about the app store python.

https://devblogs.microsoft.com/python/python-in-the-windows-10-may-2019-update/ 


I have also scanned the Windows logs for events at the time stamp from the
file and could not see anything. 

Thinking back to the 1st I did run Visual Studio 2019 Community edition at that 
time.
It was  first time on a long time and I had to login and update it.

Is Visual Studio doing the change? If so why?

Barry


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

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


Re: Python Mauritius Usergroup - End of Year report 2020

2021-01-03 Thread Alex Kaye
Super report, need more like it from others !

A.K.

On Sun, Jan 3, 2021 at 2:06 AM Abdur-Rahmaan Janhangeer <
[email protected]> wrote:

> Greetings,
>
> ^^ Thanks!
>
> Kind Regards,
>
> Abdur-Rahmaan Janhangeer
> about  | blog
> 
> github 
> Mauritius
>
>
> On Sun, Jan 3, 2021 at 8:12 AM dn via Python-list 
> wrote:
>
> > On 1/3/21 5:01 PM, Abdur-Rahmaan Janhangeer wrote:
> > > Greetings list,
> > >
> > > Here's our usergroup's end of year report for 2020:
> > > Happy reading!
> > >
> > > https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf
> >
> >
> > Well done @A-R!
> > --
> > Regards =dn
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


NumPy: build script not finding correct python version

2021-01-03 Thread Rich Shepard

I'm trying to rebuild numpy-1.18.2 using the newly installed Python-3.9.1.
The script fails when running setup.py:
Traceback (most recent call last):
  File "setup.py", line 32, in 
raise RuntimeError("Python version >= 3.5 required.")
RuntimeError: Python version >= 3.5 required.

When I invoke python3 from the command line the version is correctly
indentified:
$ python3
Python 3.9.1 (default, Dec 29 2020, 15:09:15) 
[GCC 5.5.0] on linux

Type "help", "copyright", "credits" or "license" for more information.

import sys
sys.version_info[:2]

(3, 9)




Ignoring the large explanatory comment the lines above that throwing the
error are:
from __future__ import division, print_function

DOCLINES = (__doc__ or '').split("\n")

import os
import sys
import subprocess
import textwrap
import sysconfig


if sys.version_info[:2] < (3, 5):
raise RuntimeError("Python version >= 3.5 required.")

I'm not seeing why sys.version_info is not finding the installed version
within the script and need insight from others with greater Python knowledge
than I have.

TIA,

Rich

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


Re: Does windows edit .py file shebangs?

2021-01-03 Thread Eryk Sun
On 1/3/21, Barry Scott  wrote:
>
> I've been doing some more investigation and found that the change happened
> at 01/01/2021 16:16. The shebang is pointing to a 0 length PYTHON3.EXE.

The files in "%LocalAppData%\Microsoft\WindowsApps" are AppExec
reparse points. NT filesystem reparse points are a generalized form of
filesystem link, with registered handlers indentified by a tag value
in the reparse data buffer. Various reparse-point types implement
Unix-style mountpoints and symlinks, as well as dynamic offline and
virtual files such as OneDrive.

AppExec reparse points (aka app execution aliases) have no handler in
the kernel, so they can only be accessed by directly opening them.
WinAPI CreateProcessW uses information in the link to locate the app
and create an access token that allows executing it. The app itself is
usually installed in a directory in "%ProgramFiles%\WindowsApps".

You can view the raw contents of a reparse point using `fsutil.exe
reparsepoint query `.

> Thinking back to the 1st I did run Visual Studio 2019 Community edition at
> that time. It was first time on a long time and I had to login and update it.

You could try to reproduce the scenario to see whether it modifies
your files. I wouldn't expect it to do something like that
automatically, but it does seem like the kind of 'helpful' thing a
full-service IDE would do when saving a script.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does windows edit .py file shebangs?

2021-01-03 Thread Barry Scott



> On 3 Jan 2021, at 15:13, Eryk Sun  wrote:
> 
> On 1/3/21, Barry Scott  wrote:
>> 
>> I've been doing some more investigation and found that the change happened
>> at 01/01/2021 16:16. The shebang is pointing to a 0 length PYTHON3.EXE.
> 
> The files in "%LocalAppData%\Microsoft\WindowsApps" are AppExec
> reparse points. NT filesystem reparse points are a generalized form of
> filesystem link, with registered handlers indentified by a tag value
> in the reparse data buffer. Various reparse-point types implement
> Unix-style mountpoints and symlinks, as well as dynamic offline and
> virtual files such as OneDrive.
> 
> AppExec reparse points (aka app execution aliases) have no handler in
> the kernel, so they can only be accessed by directly opening them.
> WinAPI CreateProcessW uses information in the link to locate the app
> and create an access token that allows executing it. The app itself is
> usually installed in a directory in "%ProgramFiles%\WindowsApps".
> 
> You can view the raw contents of a reparse point using `fsutil.exe
> reparsepoint query `.

Aha a reparse point! I've cleaned up too much to do this. 
I had to get back to a working state.

If it breaks again I'll use fsutils to investigate.

> 
>> Thinking back to the 1st I did run Visual Studio 2019 Community edition at
>> that time. It was first time on a long time and I had to login and update it.
> 
> You could try to reproduce the scenario to see whether it modifies
> your files. I wouldn't expect it to do something like that
> automatically, but it does seem like the kind of 'helpful' thing a
> full-service IDE would do when saving a script.

The only time I every use the IDE is when I run the debugger everything
else I do from the command line. The only reason I ran the IDE at all is
that is the way to get it to update itself.

In other words its not that it "fixed" a file I was editing. I can only think
that it was part of the updating of Visual Studio that did this.

Barry


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

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


Copying column values up based on other column values

2021-01-03 Thread Codeliner
Hello,

I have this dataframe

import numpy as np
import pandas as pd
from numpy.random import randn
df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z'])


W X Y Z
A -0.183141 -0.398652 0.909746 0.332105
B -0.587611 -2.046930 1.446886 0.167606
C 1.142661 -0.861617 -0.180631 1.650463
D 1.174805 -0.957653 1.854577 0.335818
E -0.680611 -1.051793 1.448004 -0.490869

is there a way to create a column S - which will copy column column Y values 
UP- if values in column Y are above 1 - otherwise return new value above 
zero?.I made this manually:

S:

A 1.446886
B 1.446886
C 1.854577
D 1.854577
E 1.448004


thanks a lot!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: NumPy: build script not finding correct python version [UPDATE]

2021-01-03 Thread Rich Shepard

On Sun, 3 Jan 2021, Rich Shepard wrote:


I'm trying to rebuild numpy-1.18.2 using the newly installed Python-3.9.1.
The script fails when running setup.py:
Traceback (most recent call last):
 File "setup.py", line 32, in 
   raise RuntimeError("Python version >= 3.5 required.")
RuntimeError: Python version >= 3.5 required.


Okay. Further research taught me that setup.py has been replaced with
setuptools so I need to learn how to convert the build script to setuptools
rather than setup.py.

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


Re: Copying column values up based on other column values

2021-01-03 Thread Jason Friedman
>
> import numpy as np
> import pandas as pd
> from numpy.random import randn
> df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z'])
>
> W X Y Z
> A -0.183141 -0.398652 0.909746 0.332105
> B -0.587611 -2.046930 1.446886 0.167606
> C 1.142661 -0.861617 -0.180631 1.650463
> D 1.174805 -0.957653 1.854577 0.335818
> E -0.680611 -1.051793 1.448004 -0.490869
>
> is there a way to create a column S - which will copy column column Y
> values UP- if values in column Y are above 1 - otherwise return new value
> above zero?.I made this manually:
>
> S:
>
> A 1.446886
> B 1.446886
> C 1.854577
> D 1.854577
> E 1.448004
>

Here's one solution. No consideration to performance.

import numpy as np
import pandas as pd
from numpy.random import randn
df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z'])
print(df)

y_series = df["Y"]
for i in range(len(y_series)):
if i == len(y_series) - 1:
# Last one, nothing to copy
break
if y_series[i+1] > 1:
y_series[i] = y_series[i+1]

df["Y"] = y_series
print(df)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A random word from one of two lists

2021-01-03 Thread Mats Wichmann

On 1/3/21 5:30 AM, Bischoop wrote:

On 2021-01-02, Stefan Ram  wrote:

Bischoop  writes:

On 2021-01-02, Stefan Ram  wrote:

Otherweise, I'd go this way without a dictionary.
import random
animal = ['koala', 'kangaroo']
fruit = ['banana', 'apple']
kinds = [animal,fruit]
kind = random.choice( kinds )
result = random.choice( kind )
print( result )

I had that solution in mind but I thought that one is not good
programming style or not Pythonin :-)


   I do not see any stylistic problem when you use this approach
   with "nested lists". List indexing by a number should even be
   faster than indexing a dictionary.



Now I know that's ok, seems I was ovethingking while solution was so
simply.

--
Thanks



You don't really need to do this as a two-level selection:

import random
animal = ['koala', 'kangaroo']
fruit = ['banana', 'apple']
result = random.choice(animal + fruit)
print(result)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Copying column values up based on other column values

2021-01-03 Thread Codeliner
On Sunday, January 3, 2021 at 7:08:49 PM UTC+2, Jason Friedman wrote:
> > 
> > import numpy as np 
> > import pandas as pd 
> > from numpy.random import randn 
> > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) 
> > 
> > W X Y Z 
> > A -0.183141 -0.398652 0.909746 0.332105 
> > B -0.587611 -2.046930 1.446886 0.167606 
> > C 1.142661 -0.861617 -0.180631 1.650463 
> > D 1.174805 -0.957653 1.854577 0.335818 
> > E -0.680611 -1.051793 1.448004 -0.490869 
> > 
> > is there a way to create a column S - which will copy column column Y 
> > values UP- if values in column Y are above 1 - otherwise return new value 
> > above zero?.I made this manually: 
> > 
> > S: 
> > 
> > A 1.446886 
> > B 1.446886 
> > C 1.854577 
> > D 1.854577 
> > E 1.448004 
> >
> Here's one solution. No consideration to performance.
> import numpy as np 
> import pandas as pd 
> from numpy.random import randn 
> df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z'])
> print(df) 
> 
> y_series = df["Y"] 
> for i in range(len(y_series)): 
> if i == len(y_series) - 1: 
> # Last one, nothing to copy 
> break 
> if y_series[i+1] > 1: 
> y_series[i] = y_series[i+1] 
> 
> df["Y"] = y_series 
> print(df)


Thank you Jason for this lovely for loop - is there a way to make this with 
pandas series or numpy arrays? for maximum speed?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A random word from one of two lists

2021-01-03 Thread Richard Damon
On 1/3/21 12:38 PM, Mats Wichmann wrote:
> On 1/3/21 5:30 AM, Bischoop wrote:
>> On 2021-01-02, Stefan Ram  wrote:
>>> Bischoop  writes:
 On 2021-01-02, Stefan Ram  wrote:
> Otherweise, I'd go this way without a dictionary.
> import random
> animal = ['koala', 'kangaroo']
> fruit = ['banana', 'apple']
> kinds = [animal,fruit]
> kind = random.choice( kinds )
> result = random.choice( kind )
> print( result )
 I had that solution in mind but I thought that one is not good
 programming style or not Pythonin :-)
>>>
>>>    I do not see any stylistic problem when you use this approach
>>>    with "nested lists". List indexing by a number should even be
>>>    faster than indexing a dictionary.
>>>
>>>
>> Now I know that's ok, seems I was ovethingking while solution was so
>> simply.
>>
>> -- 
>> Thanks
>>
>
> You don't really need to do this as a two-level selection:
>
> import random
> animal = ['koala', 'kangaroo']
> fruit = ['banana', 'apple']
> result = random.choice(animal + fruit)
> print(result)

It depends on what distribution of results you want. Since the example
had two equal length list is doesn't matter, but if, say, there were
many more animals then fruit, your method would produce an animal more
often than a fruit, but the two level method will make the distribution
50% fruits, 50% animals independent on the number in each category.

Which is the right answer is problem specific.

-- 
Richard Damon

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


Re: Copying column values up based on other column values

2021-01-03 Thread Codeliner
On Sunday, January 3, 2021 at 8:17:16 PM UTC+2, Codeliner wrote:
> On Sunday, January 3, 2021 at 7:08:49 PM UTC+2, Jason Friedman wrote: 
> > > 
> > > import numpy as np 
> > > import pandas as pd 
> > > from numpy.random import randn 
> > > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) 
> > > 
> > > W X Y Z 
> > > A -0.183141 -0.398652 0.909746 0.332105 
> > > B -0.587611 -2.046930 1.446886 0.167606 
> > > C 1.142661 -0.861617 -0.180631 1.650463 
> > > D 1.174805 -0.957653 1.854577 0.335818 
> > > E -0.680611 -1.051793 1.448004 -0.490869 
> > > 
> > > is there a way to create a column S - which will copy column column Y 
> > > values UP- if values in column Y are above 1 - otherwise return new value 
> > > above zero?.I made this manually: 
> > > 
> > > S: 
> > > 
> > > A 1.446886 
> > > B 1.446886 
> > > C 1.854577 
> > > D 1.854577 
> > > E 1.448004 
> > > 
> > Here's one solution. No consideration to performance. 
> > import numpy as np 
> > import pandas as pd 
> > from numpy.random import randn 
> > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) 
> > print(df) 
> > 
> > y_series = df["Y"] 
> > for i in range(len(y_series)): 
> > if i == len(y_series) - 1: 
> > # Last one, nothing to copy 
> > break 
> > if y_series[i+1] > 1: 
> > y_series[i] = y_series[i+1] 
> > 
> > df["Y"] = y_series 
> > print(df)
> Thank you Jason for this lovely for loop - is there a way to make this with 
> pandas series or numpy arrays? for maximum speed?


can something done along these lines?

df['run2'] = df['b'].apply(lambda x: df['b'].shift(1) if x > 1 else df['b'])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A random word from one of two lists

2021-01-03 Thread Mats Wichmann

On 1/3/21 11:34 AM, Richard Damon wrote:


It depends on what distribution of results you want. Since the example
had two equal length list is doesn't matter, but if, say, there were
many more animals then fruit, your method would produce an animal more
often than a fruit, but the two level method will make the distribution
50% fruits, 50% animals independent on the number in each category.

Which is the right answer is problem specific.


quite true!


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