Is CONTINUE_LOOP still a thing?

2020-06-09 Thread Adam Preble
I got to the point of trying to implement continue in my own interpreter 
project and was surprised when my for-loop just used some jumps to manage its 
control flow. Actually, I hoped for something else; I don't have logic in my 
code generation to track jump positions. I kind of hoped there was some 
CONTINUE opcode with some extra logic I could add at run time to just kind of 
do it.

(that is my own problem and I know there is no such thing as a free lunch, but 
it's 2AM and I want to hope!)

Well, I found CONTINUE_LOOP, which applies for for-loops, but 3.6.8 sure 
doesn't emit it for pretty basic stuff:

>>> def for_continue():
...   a = 0
...   for i in range(0, 3, 1):
... if i == 2:
...   continue
... a += i
...   else:
... a += 10
...   return a
...
>>> for_continue()
11
>>> dis(for_continue)
  2   0 LOAD_CONST   1 (0)
  2 STORE_FAST   0 (a)

  3   4 SETUP_LOOP  46 (to 52)
  6 LOAD_GLOBAL  0 (range)
  8 LOAD_CONST   1 (0)
 10 LOAD_CONST   2 (3)
 12 LOAD_CONST   3 (1)
 14 CALL_FUNCTION3
 16 GET_ITER
>>   18 FOR_ITER22 (to 42)
 20 STORE_FAST   1 (i)

  4  22 LOAD_FAST1 (i)
 24 LOAD_CONST   4 (2)
 26 COMPARE_OP   2 (==)
 28 POP_JUMP_IF_FALSE   32

  5  30 JUMP_ABSOLUTE   18

  6 >>   32 LOAD_FAST0 (a)
 34 LOAD_FAST1 (i)
 36 INPLACE_ADD
 38 STORE_FAST   0 (a)
 40 JUMP_ABSOLUTE   18
>>   42 POP_BLOCK

  8  44 LOAD_FAST0 (a)
 46 LOAD_CONST   5 (10)
 48 INPLACE_ADD
 50 STORE_FAST   0 (a)

  9 >>   52 LOAD_FAST0 (a)
 54 RETURN_VALUE

The place where a CONTINUE_LOOP could have made sense would be at address 30 
for that JUMP_ABSOLUTE. That'll go back to a FOR_ITER, as CONTINUE_LOOP implies 
it *must* do. I'm just guessing that at some point, somebody concluded there 
wasn't anything special about having that opcode over absolute jumps and it got 
abandoned. I wanted to check if my notions were correct or if there's some 
gotcha where having that over other things makes sense.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: From an existing Pandas DataFrame, how can I create a summary DataFrame based on the union of overlapping date ranges (given a start and an end date) and an additional column?

2020-06-09 Thread joseph pareti
i gave it a shot, see attached

Am Mi., 3. Juni 2020 um 23:38 Uhr schrieb Aaron :

> Hello,
>
> Given a dateframe with trips made by employees of different companies, I am
> trying to generate a new dataframe with only the company names.  I am
> looking to combine the overlapping travel times from employees of the SAME
> company into a single row.  If there are no overlapping travel times, then
> that row just transfers over as-is.  When there are overlapping travel
> times, then the following will happen:
>
> --The name field is removed b/c that is no longer relevant (company name
> stays), the Depart date will be the earliest date of any of the trip dates
> regardless of the employee, the Return date will be the latest date of any
> of the trip dates regardless of the employee, the charges for the trip will
> be summed
>
> For example, if trips had dates 01/01/20 - 01/31/20, 01/15/20 - 02/15/20,
> 02/01-20 - 02/28/20, then all three would be combined.  The starting date
> will be 1/1/20 and ending as of 2/28/20.  Basically, the company was on
> that trip from start to finish… kinda like a relay run handing off the
> baton.  Also, the charges will be summed for each of those trips and
> transferred over to the single row.
>
> Here is the starting dataframe code/output (note: the row order is
> typically not already sorted by company name as in this example):
>
> import pandas as pd
>
>
> emp_trips = {'Name': ['Bob','Joe','Sue','Jack', 'Henry', 'Frank',
> 'Lee', 'Jack'],
> 'Company': ['ABC', 'ABC', 'ABC', 'HIJ', 'HIJ', 'DEF', 'DEF',
> 'DEF'],
> 'Depart' : ['01/01/2020', '01/01/2020', '01/06/2020',
> '01/01/2020', '05/01/2020', '01/13/2020', '01/12/2020', '01/14/2020'],
> 'Return' : ['01/31/2020', '02/15/2020', '02/20/2020',
> '03/01/2020', '05/05/2020', '01/15/2020', '01/30/2020', '02/02/2020'],
> 'Charges': [10.10, 20.25, 30.32, 40.00, 50.01, 60.32, 70.99, 80.87]
> }
>
> df = pd.DataFrame(emp_trips, columns = ['Name', 'Company', 'Depart',
> 'Return', 'Charges'])
> # Convert to date format
> df['Return']= pd.to_datetime(df['Return'])
> df['Depart']= pd.to_datetime(df['Depart'])
>
>   Name Company Depart Return  Charges0Bob ABC
> 2020-01-01 2020-01-3110.101Joe ABC 2020-01-01 2020-02-15
>  20.252Sue ABC 2020-01-06 2020-02-2030.323   Jack HIJ
> 2020-01-01 2020-03-0140.004  Henry HIJ 2020-05-01 2020-05-05
>  50.015  Frank DEF 2020-01-13 2020-01-1560.326Lee DEF
> 2020-01-12 2020-01-3070.997   Jack DEF 2020-01-14 2020-02-02
>  80.87
>
> And, here is the desired/generated dataframe:
>
>   Company  Depart  Return  Charges0 ABC  01/01/2020
> 02/20/202060.671 HIJ  01/01/2020  03/01/202040.002 HIJ
>  05/01/2020  05/05/202050.013 DEF  01/12/2020  02/02/2020
> 212.18
>
> I have been trying to use a combination of sorting and grouping but
> the best I've achieved is reordering the dataframe.  Even though I am
> able to sort/group based on values, I still run into the issues of
> finding overlapping date ranges and pulling out all trips based on a
> single company per aggregate/overlapping date range.
>
> Thank you in advance for any help!
>
> Aaron
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Regards,
Joseph Pareti - Artificial Intelligence consultant
Joseph Pareti's AI Consulting Services
https://www.joepareti54-ai.com/
cell +49 1520 1600 209
cell +39 339 797 0644
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is CONTINUE_LOOP still a thing?

2020-06-09 Thread Terry Reedy

On 6/9/2020 3:26 AM, Adam Preble wrote:


Well, I found CONTINUE_LOOP


In opcode.py for 3.6.8 with value 119, annotated as an absolute jump.

Everything in this file is use-at-your-own-risk internal cpython detail, 
subject to change with any release.



3.6.8 sure doesn't emit it for pretty basic stuff:


It is gone in 3.8.3, along with others.  I believe a core developer who 
added new opcodes removed unused opcodes after counting emissions of 
opcodes in compiler code.  As with Python, deletion of unused items is 
not guaranteed to be immediate.


SETUP_LOOP, which was used in 3.6, is gone also.

--
Terry Jan Reedy

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


Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-09 Thread Cousin Stanley
Caledonian26 wrote:


> However, I keep getting the error: 
> 
>   IndexError: list index out of range. 
> 
>  Could anyone give me a helping hand 
>  as to where I am going wrong?
> 

  I appended a single arbitrary value for limits  
  since the  limits  list had not been previously
  initialized  
  
  

  colourofbars = [ ]

  for key , value in dict_means.items() :

  limits.append( 3000 )

  if limits[ 0 ] > ( key + ( value ) ) :
  

  This fix gets past the  index out of range  error
  and produces a plot which might let you proceed
  to the next problem you might encounter 


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Python-list Digest, Vol 201, Issue 9

2020-06-09 Thread Joseph Jenne via Python-list

On 2020-06-09 09:00, [email protected] wrote:


Well the problem that I am facing with is, that I have to establish interface 
between python and outer system.

Original question was about creation of input object (data that I have received from outer system). 
If I accept recommendation to use "from_" instead of "from", it could work, for 
processing input, because processing is under my control.

However, my process will create output object that I should json serialize and return back to outer system as a 
response to the input. If I will have "from_" object property instead of "from", I believe that I 
should write a custom object to json serializer in order to support changing names from "from_" to 
"from".


It should be possible to name it from_ and then insert it into the __dict__ as 
'from', although a custom serializer
would probably be preferable from a design standpoint.

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


Re: Python-list Digest, Vol 201, Issue 9

2020-06-09 Thread Rhodri James

On 09/06/2020 18:31, Joseph Jenne via Python-list wrote:

On 2020-06-09 09:00, [email protected] wrote:

Well the problem that I am facing with is, that I have to establish 
interface between python and outer system.


Original question was about creation of input object (data that I have 
received from outer system). If I accept recommendation to use "from_" 
instead of "from", it could work, for processing input, because 
processing is under my control.


However, my process will create output object that I should json 
serialize and return back to outer system as a response to the input. 
If I will have "from_" object property instead of "from", I believe 
that I should write a custom object to json serializer in order to 
support changing names from "from_" to "from".


It should be possible to name it from_ and then insert it into the 
__dict__ as 'from', although a custom serializer

would probably be preferable from a design standpoint.


Might it be simpler to use a dict from the start?  You could have a 
dictionary key of "from" without any problems.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 3.9.0b3 is now available for testing

2020-06-09 Thread Łukasz Langa
On behalf of the entire Python development community, and the currently serving 
Python release team in particular, I’m pleased to announce the release of 
Python 3.9.0b3. Get it here:

https://www.python.org/downloads/release/python-390b3/ 

Wait, Beta 3? What happened to Beta 2?

Beta 2? Speak of him no more. We disappeared him. He was a bad release. Truly 
awful. I get shivers just thinking about it. Never mention that name again in 
this house.

I mean, long story short, in Beta 2 you couldn’t do 
urllib.request.urlopen("https://www.python.org";).read() because it wouldn’t 
find root certificates due to a bug . Since 
this was a problem only apparent on an installed Python, it wasn’t identified 
by unit tests and was only found by Ned while he was testing his Mac installer. 
By the time we learned of the severity of the bug I already tagged and 
published the release on python.org . That’s why we 
couldn’t just re-do the release under the same version.

Sorry for the trouble. We’re tweaking our release process to catch this problem 
sooner in future releases. Now, back to regular programming…

This is a beta preview of Python 3.9

Python 3.9 is still in development. This release, 3.9.0b3, is the third of five 
planned beta release previews.

Beta release previews are intended to give the wider community the opportunity 
to test new features and bug fixes and to prepare their projects to support the 
new feature release.

Call to action

We strongly encourage maintainers of third-party Python projects to test with 
3.9 during the beta phase and report issues found to the Python bug tracker 
 as soon as possible. While the release is planned to 
be feature complete entering the beta phase, it is possible that features may 
be modified or, in rare cases, deleted up until the start of the release 
candidate phase (2020-08-10). Our goal is have no ABI changes after beta 5 and 
as few code changes as possible after 3.9.0rc1, the first release candidate. To 
achieve that, it will be extremely important to get as much exposure for 3.9 as 
possible during the beta phase.

Please keep in mind that this is a preview release and its use is not 
recommended for production environments.

Major new features of the 3.9 series, compared to 3.8

Some of the new major new features and changes in Python 3.9 are:

PEP 584 , Union Operators in dict

PEP 585 , Type Hinting Generics In 
Standard Collections

PEP 593 , Flexible function and 
variable annotations

PEP 602 , Python adopts a stable 
annual release cadence

PEP 616 , String methods to remove 
prefixes and suffixes

PEP 617 , New PEG parser for CPython

BPO 38379 , garbage collection does not 
block on resurrected objects;

BPO 38692 , os.pidfd_open added that allows 
process management without races and signals;

BPO 39926 , Unicode support updated to 
version 13.0.0;

BPO 1635741 , when Python is initialized 
multiple times in the same process, it does not leak memory anymore;

A number of Python builtins (range, tuple, set, frozenset, list, dict) are now 
sped up using PEP 590  vectorcall;

A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, 
_functools, _json, _locale, operator, resource, time, _weakref) now use 
multiphase initialization as defined by PEP 489 
;

A number of standard library modules (audioop, ast, grp, _hashlib, pwd, 
_posixsubprocess, random, select, struct, termios, zlib) are now using the 
stable ABI defined by PEP 384 .

(Hey, fellow core developer, if a feature you find important is missing from 
this list, let Łukasz know .)

The next pre-release, the fourth beta release of Python 3.9, will be 3.9.0b4. 
It is currently scheduled for 2020-06-29.

More resources

Online Documentation 
PEP 596 , 3.9 Release Schedule
Report bugs at https://bugs.python.org .
Help fund Python and its community .
Your friendly release team,
Ned Deily @nad 
Steve Dower @steve.dower 
Łukasz Langa @ambv 
-- 
https://mail.python.org/mailman/listinfo/python-list