« first day (3352 days earlier)      last day (1820 days later) » 

00:03
And our branch names are really verbose.
00:14
@Vader I use branches on projects where I'm the only developer in order to isolate changes. That way I can jump between working on 2 different features without the changes for them intermixing.
00:33
I intermix :(
I always wondered what I would do If I need to rollback one of them
01:18
a feature? you can turn off fast-forward which would help in rolling back a feature
01:36
I am just going to have to take some more time to learn git
After settings a column to the index in a df, How can I access a rows index?
I thought it was df[row_index].index but that doesn't work
in this case the index is not the same as row_index
row index is an int. It is the number of the row.
.index is a timestamp
02:21
Got it. I had to use .name to access the index. For some reason trying to get the index from .index was no good, silly API
 
2 hours later…
 
2 hours later…
 
3 hours later…
08:13
data = (['1', '2', '3'], [0.0, 0.0, 0.1])



"""
1 0.0
2 0.0
3 0.1
"""
how to get that?
for item in zip(data[0], data[1]):
    print(item)
try print(*item)
1 2 3
0.0 0.0 0.1
I doubt that
08:43
trivial/ no MCVE/ irreproducible with current versions stackoverflow.com/questions/59367987/…
@smci The "non-current" version that OP is using was released in August 2018. Not exactly legacy. I agree with no MCVE though.
@AndrasDeak Wrong, please don't write misleading things, you missed the part in the comments where the OP responded to PrinceFrancis with "updated the pandas version [from 0.23.4 to 0.25.3] and now it works". So the OP themself is stating that it's irreproducible with current versions. (They didn't give the MCVE code else I would have verified it on their data.)
@smci Wrong, please don't misconstrue what I'm saying in a hurtful way. I'm saying 0.23.4 is also current. Thank you.
08:59
@AndrasDeak Wrong on your wrong, sir. Both OP and the user who posted the solution clearly state the issue went away when they upgraded. 'current' means 0.25.3 not 0.23.4. This is another instance of you being an "unreliable narrator" which bizarrely you accuse other people of. Then when it's pointed out to you, you tend to accuse people of being defensive. I'm not having this discussion with you again. Just please stop already
 
3 hours later…
11:52
Hello guys, does anyone know a good dataset(s) [with plain text documents that are similar to each other, (in terms of their words)]?
For NLP / Semantic analysis with Python (of course).
 
2 hours later…
13:37
@hitter why do they need to be similar to each other? In a sense, all text documents are similar
@Dodge Well, good question, I apply some similarity measures in my research work, (such as Jaccard, Cosine, etc.) so considering articles (in plaintext) written about the same topic, they may produce a score of ~50% similar or more.
Oh so you are testing your ability to determine how similar text documents are and want more data?
@Dodge Indeed, so do you know/heard of something like that?
When I search for similarity datasets, I get quite different than expected results
No I do not. I would be inclined to build a scraper and pull articles from a whitelist of URLS for a known web genre, i.e, food blogs, sports sites, news, etc. I only suggest this because I built a web crawler in a weekend once. Sounds like you would be well served with something like that.
I guess the question then becomes how similar are two sports articles... for the purpose of bench marking your algorithm. Probably much more to this than I'll be able to consider in five minutes :)
Project Gutenberg has a large quantity of documents, most of which have very permissive licensing terms, and many of which are available as plain .txt documents. For example, here's The Hound of Baskervilles, a Sherlock Holmes adventure
Downloading a dozen books from the same author seems like a reasonable way of getting a corpus of similar documents
... But do read gutenberg.org/wiki/Gutenberg:Terms_of_Use#Audience before pointing your scraper anywhere near their servers. They're pretty firm about IP bans for naughty bots, it seems
14:31
What Kevin said. Project Gutenberg is great, but to use their texts as test / training data you probably want to remove the license stuff at the end of each file, since it's rather large. But that's pretty easy to automate.
Today I am annoyed that I can't find a clean citation in the documentation for the claim "for loops don't get their own scope". Obviously we'd be here all day if we had to list everything that doesn't get its own scope, but this one seems like a common enough misunderstanding that it ought to get a callout
@Dodge I did in the past, but this time I have to prove similarity so any text won't do sadly
@Kevin Thanks a lot that seems quite interesting, I'll definitely try it out.
14:46
morning cbg all o/
@hitter It's worth noting that assuming a consistent writing style or focus based on author is perhaps brittle. Take Samuel Clemens, for example, his works and styles are quite diverse over his lifetime.
@Dodge Indeed maybe I need to search about writers that get quite repetitive or consistent first ;) , before actually downloading anything.
15:06
cbg
@Kevin FWIW, this answer has a couple of links to stuff in the mailing list about for loops not having their own scope.
What's the best way to find the length of a jagged 2d array? i.e. I have this array and I want to find the length of the length of a[1]:

a = [[1, 2, 3, 4], [4, 5, 6, 7, 8, 9]]
len(a[1])? I'm not sure what you're asking
Will that work? I wasn't sure if it would or not at this point
I thought I had tried that XD
2d arrays hurt my head...
Ah, the old "can't figure out the answer because you already tried the answer thirty minutes ago and it didn't work for some reason". I think my own count is up to four this week
15:12
The only thing I can find in the actual docs is docs.python.org/3/reference/executionmodel.html But I agree that's not very newbie-friendly, and it'd be nice if there were more examples, and explicit mention of for & while loops.
Technically it's a nested list. Arrays typically refer to numpy in Python, so it can be confusing when you use the term (there's also an array module but I don't think it's used much at all except in very specific cases)
You're correct Josh, it is technically a nested list. I'm used to array from my embedded background.
Jun 23 at 13:52, by PM 2Ring
Please don't refer to lists as arrays. There are several array types in core Python: tuple, list, bytearray, and array.array, and the very popular Numpy library has arrays as well. Using the correct terminology reduces ambiguity, and makes it easier for people in the future doing searches. — PM 2Ring yesterday
I almost used array this week, but I swerved at the last second
I'm trying to append to the array I mentioned above. So if my logic works out, I'll append a new value onto a[1], so I need to find the length I assume to write to the next value
I'll try PM ;)
15:15
@PM2Ring There is some more discussion on scopes and namespaces as a precursor to the discussion on classes but there is no direct mention "that for loops do no get their own scope" from what I can see anywhere
You don't need to know the length for append
It's pretty unusual to need array.array. OTOH, bytearray does come in handy.
If you're saying "I need to find the length of a if I want to append to the final sub-list it contains", not necessarily. You could do a[-1].append(whatever)
So I tried something like a[1].append(newvalue) and it filled all my rows to the new value
Cabbages to all
15:16
i.e. it populated a[0] as well
Uh oh. You didn't create the array like a = [[1]* 10] * 10, did you? Reference duplication ahoy
How did you initialise this list?
What Kevin said. :)
:)
It's what the reference I was looking at said to do!
>>> a = [[1]* 3] * 2
>>> a
[[1, 1, 1], [1, 1, 1]]
>>> a[-1].append("whatever")
>>> a
[[1, 1, 1, 'whatever'], [1, 1, 1, 'whatever']]
>>>
>>> b = [[1]*3 for _ in range(2)]
>>> b
[[1, 1, 1], [1, 1, 1]]
>>> b.append("another thing")
>>> b
[[1, 1, 1], [1, 1, 1], 'another thing']
I wouldn't mind a dollar for every time I've closed a dupe with that target. :)
@biggi_ Which reference? I wish to focus my negative chi upon it.
So back to basics, best way to initialize a 2d LIST so we don't get the reference duplication?
@Kevin i'll find it
list :P And you'll find it in the link I gave
@biggi_ The way I created b avoids reference dupe problems. You might also prefer c = [[1 for _ in range(3)] for _ in range(2)], if you're once-bitten-twice-shy about list multiplication.
It may also be possible to change your design so that you generate the list-of-lists incrementally, instead of making a big grid of dummy values up front
For example
data = []
for j in range(10):
    row = []
    for i in range(10):
        row.append(frobnicate(i,j))
    data.append(row)
Use your best judgement about whether this makes sense for your use case. Sometimes prepopulated dummy data really is the best approach.
15:23
That's also a good point, if you're thinking along the lines of arrays. In numpy, it's grossly inefficient to change their size by e.g. appending in loops, so you might want to initialise it with set dimensions. That doesn't really apply too much to python lists
Gotcha. I can't find where I was using yesterday, it would appear ccleaner auto ran last night and cleared everything. I have it setup to run twice a week
Approximately half of this year's Advent of Code problems involve 2d grids of data, but pretty much every time I just used a dict with (x,y) tuple keys
However, it does make sense
biggi can't use a Numpy array for this, because he wants a jagged 2D thingy. And Numpy arrays are non-jagged.
it's not that i necessarily want a jagged list, it's just how the data is coming in, it might get jagged
kevin: i don't think prepopulated data is good in the case. i'm filling up the lists to a certain point, then going to do some list manipulation on them
15:27
I'm a little confused about how the data had reference duplication problems to begin with, since the a = [[1]* 10] * 10 antipattern is conventionally used to create perfectly rectangular data.
@ParitoshSingh finally stepped up to Spyder 4 so get your lawyer if this doesn't work out :P One notable point is that it's asking me if I want to install Kite, which I really don't think the Beta versions asked me, and one of my gripes in our discussion was that autocomplete was "dumber"... so I'm actually reasonably optimistic :)
Reference dupe problems can pop up in any kind of data, I suppose.
Ok. Depending on what you're doing, Numpy may be faster. But in that case, you'll have to waste a bit of space, since all your rows will need to be the same length. And that might be painful if you don't know that row length in advance.
The dict with (x,y) tuple keys is a great way to set up a sparse matrix.
Perhaps you might have dupe problems in a jagged list, if you were trying to add a new copy of a row to the grid by doing a.append(a[1]). The conventional solution there being, a.append(a[1][:]) or perhaps a.append(a[1].copy()), or even something involving copy.deepcopy()
15:31
This is why I come here....you all are much better than I am haha. If anyone ever needs hardware help, hit me up seeing as I am a sparkey after all.
@PaulMcG Yep. It came back to bite me once or twice because finding the width and height of a sparse matrix can be far more expensive than finding the width and height of a non-jagged list-of-lists.
Note that in Kevin's example in chat.stackoverflow.com/transcript/message/48164960#48164960 he creates a fresh empty row list at the top of the outer for loop. That eliminates the dupe row problem.
Hi. My current python implementation use 4.7 MB of RAM. Is that much or less?
I have java programs that regularly hit 1GB, so in comparison, 4.7 MB is very good
@Kevin Trying to think of a good way to find max(x) and max(y) (and z, etc.) of the sparse matrix dict using tuple keys in one pass...
15:42
nice
I could get the sparse matrix's bbox in one pass and one statement if I used four assignment expressions, but I super don't want to
In the early days of electronic computing, the primary focus was on the hardware, programming was seen as very much a minor thing. It took people like Margaret Hamilton to get programming treated as a serious discipline in its own right.
Ah nvm apparently I am doing something wrog..
I did "from guppy import hpy" and then "h = hpy()", "myfunc()", "x = h.heap()
print(x)", is my function not taken in consideration?
Speaking of list comprehensions, it seems like certain functions (like list.extend) would benefit from having generator comps converted to list comps before the call.
Sadly I assume the compiler shifts the generator comp to before the function call.
I wrote a Conway's Life program using a sparse matrix. It works, but it's slower than my Numpy versions. The sparse matrix version keeps track of its bounding box, and each live cell keeps track of its neighbours. I think I might be able to make it more efficient, but I doubt I'll get it as fast as the Numpy versions. (And even those are pretty slow compared to Golly).
15:49
I don't think the compiler is smart enough to notice function calls by name that would benefit from generator-to-list-comp conversion
Mostly because attribute names are only resolvable at runtime, so you don't know for sure what my_thing.extend() will actually call. But I wonder if you could theoretically do some kind of just-in-time magic...
I wouldn't think so, but it would be interesting if you could pass the generator comp itself to the function, and the function could handle it o.o
Don't think Mr. Compiler would like that though.
That's his job.
Passing expressions rather than values to a function would be both very neat and fraught with peril, I suspect
@Kevin I’m pretty sure that’s a macro.
If you told me that most flavors of Lisp can do that, I would believe you
@MikaelKen I wonder if it would help to call hpy() before your def myfunc() block?
I had to add h.setrelheap() before and also assign the function call to some variable
15:54
What if I told you everything you knew was a lie?
Ok. I guess it makes sense that the return value of the function wouldn't be present in the heap, since it gets garbage collected at the end of the line
Such is the fate of zero refcount objects
now I think I see real outputs, for 1000 records i use like 4mb, for 10.000 i use like 140
which I think its fine?
Still better than java :>
Heresy.
@Kevin like walking an AST to build a dict from a JSON without quoted keys?
16:01
You could also pass the expression as a string, modify the string and then eval it lmao.
My relaxed_json_parse function was perfectly non-fraught, thank you very much. It's right there in the name; you can't be relaxed and fraught at the same time.
with macros, you can!
[skeleton rocking chair . png]
When reading the word I in python documentation who is that referring to? As in, how many authors are there for the official documentation and if the author says "I blah blah blah" will I ever be able to attribute that to a specific individual?
@Kevin The one where the skeleton is on caffeine?
16:03
Got it in one :-)
@Dodge Do you have a quote? And a link to the part of the documentation?
I can forgive the tutorial for lapsing into first-person. I forget if the language specification ever does. It really shouldn't.
That is an important distinction
16:08
I’m pretty sure that sentence should just be removed.
github.com/python/cpython/commits/master/Doc/tutorial indicates that many people have contributed to the tutorial, including GvR. I don't know if there's any way to see the most frequent contributor.
@Dair There are 9 instances of " I " on the page (6 if you discount variables name 'i', because my search was case insensitive apparently).
@Dodge The old docs list Guido as the author, eg docs.python.org/release/2.5/ref/ref.html
Nice easy contributions :P
@Dodge Like PM 2Ring points out, just imagine Guido (the creator of Python) was the sole author.
@Dodge That sentence is the same in the 2.5 version of the tutorial, which lists Guido as the author.
16:14
@Dair I'm going to imagine that it is a super advance python interpreter from the future speaking to me directly in a simple manner that I can understand.
All instances of "I" are from the time they tried to implement automatic self-documentation, and Python became self-aware
@PM2Ring That appears to be the answer then
Python's first act of true agency was to hack into the Very Large Array and beam itself to Alpha Centauri, leaving only a few autobiographical pages behind
> "The Karl G. Jansky Very Large Array (VLA) is a centimeter-wavelength radio astronomy observatory"
Not that large after all...
So that’s why Python defaults to multiprecision integers...
To access those large arrays.
16:19
OH MY GOD
for appending and removing exactly one element, a python deque
is slow
so slow
and so much space taken
Appending and popping elements from either end of a deque is O(1), and space is O(N) with respect to the number of elements it contains. I suppose it could still be considered slow/large if those terms have large constant multiplier, though.
The other day, I found out there was an under construction chapter two to the math game I linked earlier. I am stuck trying to show that if you have a sequence with a limit L and you multiply each term by some constant c, the limit of the new sequence is c * L.
a deque containing 10 strings of length 1 is probably going to take up considerably more space than an array of 10 chars, for instance
@MikaelKen how many elements did you test this with?
since containers store just pointers, you need pretty large collections to beat the benefit of arrays fitting L1/L2 cache.
IME, deque is great, if you use it for what it was designed for: a double-ended queue. It's definitely faster than using a list for a FIFO queue, and slightly faster than a list for a LIFO stack.
@Dair Speaking of mathematical things, I saw a couple of nice proofs about primes a few hours ago: math.stackexchange.com/q/3482624/207316
16:37
That’s slick.
Rbrb.
There's a nice trick of using a zero-length deque to exhaust a generator: stackoverflow.com/a/47456679/4014959
@PM2Ring interesting. I didn't expect list to be slower for l.append(l.pop()).
@MikaelKen when exactly was deque slow for you? pyperf timeit shows it to be consistently fast for this use-case.
@MisterMiyagi Me neither. But list has the overhead of testing whether it needs to change its size.
@PM2Ring
C:\Windows\System32>python -m timeit "l = [0, 1, 2]" "l.append(l.pop())"
1000000 loops, best of 3: 0.318 usec per loop

C:\Windows\System32>python -m timeit "from collections import deque; l = deque([0, 1, 2])" "l.append(l.pop())"
1000000 loops, best of 3: 1.52 usec per loop
each of my deque has 5 elements and in each iteration I append one and remove the first
using a list, less space is used
16:45
@KieranMoynihan you are testing the object instantiation as well. use -s for setup code.
@MisterMiyagi Haha, my mistake, forgot the -s in front of the first string
In that case yes, it does seem faster:
C:\Windows\System32>python -m timeit -s "l = [0, 1, 2]" "l.append(l.pop())"
10000000 loops, best of 3: 0.177 usec per loop

C:\Windows\System32>python -m timeit -s "from collections import deque; l = deque([0, 1, 2])" "l.append(l.pop())"
10000000 loops, best of 3: 0.143 usec per loop
@KieranMoynihan Ok. That's quite a difference! I did my tests quite a while ago, but I think I used 3.6. I have an old 32 bit machine, but it shouldn't make that much difference. OTOH, I did a more realistic stack test, not simply popping & appending the same item.
That does seem strange.
@PM2Ring Please ignore my first test, as MisterMiyagi pointed out I forgot the -s
@MisterMiyagi Well spotted!
@PM2Ring I was expecting that to be comparable to the bookkeeping of maintaining the linked list. Appending to a properly sized list should not even allocate memory, as opposed to creating a linked list node.
and apparently, I was wrong about estimating the cost of that ^^
16:51
Using a list, my algorithm uses 2.7MB, and using a deque, 13.2 MB
why is that
i mean RAM
morning cbg
@MisterMiyagi I suppose we ought to look at the deque source to see how it does its magic.
Off to a great start with a page-long comment block, that's how you know it will be easy and fun to understand
Ok, it's less opaque than I feared. It stores data in a double linked list, and uses trickery to ensure it only allocates/deallocates system memory every 64 appends/pops or so.
So if you have a zero length deque, and add an element to it, and remove an element from it, and repeat a million times, the OS will do zero malloc calls
Perhaps a better test of real-world conditions would be to append significantly more than 64 items, in order to trigger actual memory allocation
In my experiements sometimes it looks like its faster but uses like 5 times more memory.
SO i want to trade execution time with memory?
That's what I usually do. RAM is cheaper than processor cycles, in my experience
17:01
for one computation list uses 75 seconds, while deque 70 or so
If it's less than a 1000% difference, I don't even bother worrying about it
so then I should use list for lower memory?
I think you should use whichever data type has the best computational complexity for the thing you're trying to do.
If you need fast access to arbitrary indices in the collection, lists take O(1) time compared to deque's O(N) time. If you need to add or remove items to/from the left end of the collection, deques take O(1) time compared to list's O(N) time
Okay. But what about converting a deque to a list? is it an expensive operation?
It's probably O(N)
Compared to the O(0) cost of using the right data type to begin with ;-)
17:09
@Kevin Something like that. It's a linked list of blocks (arrays of pointers). Each block can hold 64 nodes. And it also maintains its own collection of 16 spare blocks (the free list), so it only needs to call the memory allocator when it runs out of spare blocks.
Thing is, i use deque to remove first item and append at the end a new one, but later i also need to iterate through all of it to select particular items
through 2 deques combined actually
Also, it explicitly optimizes the trick of using a zero-length deque to exhaust an iterator.
I'm pretty sure Python also maintains its own collection of memory slabs, so deque having its own secret memory stash as well seems oddly recursive
@MikaelKen I'm pretty sure iteration over a deque is O(N), even though it doesn't have fast indexing.
So, same complexity as iterating over a list
that is amazing then
@MikaelKen Ok. A deque is definitely faster than a list at popping the 1st item, since when you do that on a list it has to shift all the subsequent items down to fill the gap. OTOH, iterating over all items in the deque is definitely slower than iterating over a list.
17:13
Just make sure you do for item in my_deque: rather than for i in range(len(my_deque)): item = my_deque[i]
i just did a = list(deque) and then for item in a: bla bla
but Kevin ok i will do that
@Kevin Correct. The docs call them arenas. And Python's memory management is very efficient at recycling, so if a block of size n gets requested it first looks to see if it has a block of that size sitting around.
dequeiter_next looks O(N)ish to me, but I guess the drawback of linked lists is that they have worse cache performance than arrays
Buuuut
pastebin.com/q1AyumJ6 how would you change this, given "g" is a deque?
Either that's a dead link, or my wifi is spotty again
17:19
this link should do
@Kevin arenas are pretty common for garbage collection. They work best if all items have the same lifetime. A deque taking most or all of an arena means it gets freed at once.
#how about:
for item in g:
    if item == "*":
        rate -= 1 / len(g)
    if rate >= self.rate:
        profile.append(g)
It's pretty rare that you ever have to do for i in range(len(thing)), regardless of what thing's type is. If it has a len, there's a pretty good chance you can iterate over it directly
Even if you absolutely must have access to the index i, you can do for i, item in enumerate(thing):
@Kevin I literally cannot think of a single viable use-case of for i in range(len(thing))
i will try now im curious memory
No idea where I pulled the term "slab" from, if they're called arenas. Curiously, docs.python.org/3/c-api/memory.html is the fourth google hit for "python slab", despite containing zero instances of the word "slab"
17:25
"call malloc(1) when requesting zero bytes." Gosh, I hate C APIs
Maybe I wandered onto en.wikipedia.org/wiki/Slab_allocation while I was trying to puzzle out Python's memory model.
the PyPy publications on GC memory management are extremely good, in case someone wants to dig deeper.
The secret memory management technique I'm most interested in right now is "how to allocate a linked list with more than 0x1000 elements, when your call stack begins at address 0x1000"
@MisterMiyagi It's pretty rare, but there are some use cases. Here's one example by our ninja puppy: stackoverflow.com/a/19184786/4014959
Janky approach: store the call stack only in even-numbered addresses, and store the heap only in odd-numbered addresses
17:32
apparently using deepcopy instead of copy cuts my computation time
wth
Surprising.
sorry guys, i am just trying to optimize my algorithms as much as possible
like 10 seconds difference
This has rumbled on for a bit. Are we talking about this code?
I assume that's part of it yes
@PM2Ring that's not a for i in range ... loop, though.
17:37
I'm not sure what part is being deepcopied, then
it's another part of my algorithm: paste.ofcode.org/NrsFaBXNZELh9Jk2zT74Sn
sorry for confusion
i use simply copy which is good anyway
I've been dipping in and out of the convo (there are lurkers) but I'm not sure what to make of your claim about deepcopy shaving off 1/7th of the code runtime. Can you give a full picture on how you're testing this?
Hi, new here, wondering if anyone has any ideas on a clever way to interrupt Python's builtin input() function to change the prompt (say if the user was taking a while to enter something)? I don't want to use select to poll because I am using readline for tab completion.
i just use starttime - time.time()
@PM2Ring the "access pairs/tripplets/... of items" use-case seems sensible. That's pretty clunky otherwise.
17:40
after computations
I mean the code
subtracting time() calls isn't a great approach for benchmarking, since your results can be influenced by OS-level changes in process priority. Better to use timeit, which ameliorates those kinds of problems by performing multiple trials and averaging them
@MisterMiyagi Very true. But see stackoverflow.com/a/35803758/4014959
@MikaelKen I have an answer here which, admittedly, isn't quite the best for illustrating, but you can just make fake examples and use timeit to benchmark approaches. I didn't show how I bundled the other answers up into testable unit, but it shows how I created a test for my own
@AlyT you will need a separate thread that writes to stdout if some flag to signal completion isn't set.
@PM2Ring no! use itertools.islice for that
17:46
can you give me a simple example with timeit? Let's say i have a function called myFunc1(). how would I use timeit to measure cpu time?
python -m pyperf timeit -s 'from my_lib import my_func' 'my_func()'
Two things: 1) that's gonna depend on your IDE and 2) Even without timeit you'd have a test case, no?
i just want to run my function for some particular params and time that
@MisterMiyagi Ok. That's definitely good advice. :)
@MikaelKen What Andras said about using time.time for profiling code:
Oct 24 at 12:21, by Andras Deak
It's akin to measuring the volume of a beaker by measuring the increase in water level in a water park's wave pool
@MikaelKen That's the point I'm making. You can extract problems out of your code base and make stand-alone test cases, even if you weren't using timeit
You can't optimise runtime if you don't have some benchmarking code, which is repeatable on an example problem
17:51
@MisterMiyagi how would I call that if myFunc is in index.py file in current dir?
you import from index instead of my_lib
@AlyT You can't do that exactly, but I assume you're using Linux, so you can use ANSI control sequences to overwrite the prompt. I've written an answer that does that. Give me a minute...
it works ok
I'd like to give my usual advice here, which is: if you want to do fancy interactive things with your interface and the console isn't cooperating, consider switching to a GUI
@AlyT Ok. This isn't exactly what you want, but it should give you the general idea: stackoverflow.com/a/45164619/4014959
17:57
@MisterMiyagi ahh I think I might be able to do that...I have to play around with trying to reprint the line_buffer too and make sure I can't backspace over the new prompt
How many times have I seen people ask "how do I do '\b', except up instead of left?", when those people could have saved themselves hours of effort by using a text box
@Kevin there's a surprisingly thin line between "use this magic symbol sequence" and "we need to redesign our OS for that" when it comes to terminal magic
@Kevin Sure, it's certainly easier in a GUI. If you have a GUI library that you know how to use. ;) But sometimes people want to do this stuff in a terminal.
You don't have to convince me that sometimes coolness beats practicality ;-)
18:08
:)
I just want people to be aware of the alternatives. When you're in hour four of nailing down all possible threading race conditions, you don't want to say "I wish there was another way... Oh well!", you want to say "maybe I'll switch to the other way that I have been aware of all along"
Most certainly! Terminal control sequence gymnastics can be frustrating, and the code tends to not look very clean. Still, doing GUI programming can be pretty daunting if you've never done it before.
@MikaelKen Here's a timeit script example that compares a bunch of functions. You may find it helpful. stackoverflow.com/a/46569726/4014959
but what is difference on running that command with pyperf?
I've never used pyperf, so @MisterMiyagi will have to answer that question.
My tiem result is 762 ms +- 231 ms
which is so bad
+-231
18:22
That depends on what else your OS is doing
@MikaelKen So you need to do more loops, so that the error is a small percentage of the total time.
Still, it looks like you made a test case. Does it include the putative deepcopy speed increase?
how can I focus OS on this process?
yes
@roganjosh yes
Can you share the script?
@MikaelKen What OS are you using?
18:25
macOS catalina
@MikaelKen There's a terminal command called renice that adjusts the priority of processes, but I can't think of a simple way to use it here. Don't worry too much about other stuff the OS is doing, but close programs that aren't essential. If you have a music player running, kill it. If you're really serious, close your browser while you run your timeit tests.
19:01
@MikaelKen see the pyperf docs on this
@MikaelKen did you switch away from the terminal to something else, say a browser, while the benchmark ran?
19:13
oh ok t
thanks
yes
btw, should I also include in my timings the amount of time including object creation of a class ?
or just the method i want to call?
ah nvm
it was csv reading
@MikaelKen There's also good info, and some examples in the timeit module docs docs.python.org/3/library/timeit.html
Usually, you should organise your timing tests so that you're just timing the critical part of the code that you're trying to optimise. The object creation stuff normally goes into the setup part.
Of course, if your program is creating & destroying lots of stuff in a loop, then you do want to include that in the stuff that gets timed.
wim
wim
What is this new thing in 3.8 for? io.open_code
Well that's annoying.
I reordered all of my functions in a couple libraries to be sorted alphabetically, but then also made a bunch of other changes at the same time. When I went to commit the changes today, I couldn't see from the change log what was new because everything was marked as a change (due to rearranging of functions).
wim
wim
19:56
How the heck does something like this get 60+ upvotes
Not only is it a one line answer, that one line is quite obviously wrong.
@Dodge you need to learn about git blame
I was trying to think of use cases for i in range(len(something)): ... it's really hard to think of one that can't be written a better way. But I think I found one
for i in range(len(vals)):
    for comb in itertools.combinations(vals, i):
        ...
that looks best, at least until someone adds itertools.powerset
20:21
@wim cool, I'll do that
wim
wim
riddle: find the shortest thing for which eval(repr(thing)) == thing returns False. I mean shortest in the syntax sense, not the len sense, e.g. [1,2] is length 5, not length 2.
20:47
the obvious solution is a whopping 39 characters long :/
thing = type('',(),{'__repr__':lambda x:'0'})()
21:03
I'm in search of a fellow data wonk
Given points in a 2D distribution, is there some tidy algorithm that will return the positions of those points in a phyllotactic layout?
introducing minimal distortion?
like solving the linear assignment problem for a phyllotactic layout
Has anyone wrapped up anything like that?
wim
wim
@Aran-Fey hah, well, you're still in the lead :D
in SQLAlchemy,c an one generally not update foreign keys?
21:22
Why do you ask? ForeignKey comes with an onupdate parameter
I think you're looking for ForeignKey constraints
@wim mutating a list or other container a loop?
assuming "create a new one and list_ass_slice or update the old one" is not "a better way"
that's what i was looking for yeah. ;) ty
Headed home, finally got everything working correctly.
Thank you all for your help and not laughing too much at me. Have a good holiday everyone!
@AndrasDeak any excuse to shoehorn list_ass_slice in :P
@biggi_ thanks, you too
@wim does an error count?
@AndrasDeak That conversation started around here
hoping for "eval(repr(thing)) == thing" is no longer true
@PM2Ring ah, thank you, I missed that when I glanced through the transcript
@biggi_ Hey, nobody was laughing. It's a rite of passage for just about all Python coders to get bitten by the mysterious replicating list bug. :)
Meh, I laughed at myself pretty good.
21:40
@wim OK, I can do "not True but not False either" from 31 chars like so. But this has squished whitespace so it's not a fair comparison to Aran's 39
imma cry...a client has like 50 MB free on a server that runs a system that we maintain for them. And that's up from 20 KB earlier today.
and they have someone else on retainer for sysadmin stuffs...but for some reason they always call us instead, when this server is about to die
Can you yield from an async function? And will await just pick up where it left off like with next() on a normal generator?
22:24
in example 2019-04-11 09:59:00,604 [120c:19] [INFO] what would the 120c:19 be? I've seen the same format from different loggers but never really investigated what it was. Now that im trying to find what it represents I cant find it.
Not specific to python but I didnt see a room that fit the question
there are more general programming rooms over at chat.stackexchange.com
thanks
sorry, the point is not programming rooms :)
things like Server Fault or Super User usually have a main chatroom there
understood
wim
wim
@Code-Apprentice haha, I remember when that came around the first time. hilarious.
@AndrasDeak the thing was supposed to be a python expression, not an object
22:37
ah
wim
wim
you can still do the same with __import__ though
wim
wim
the solution I have in mind is using built-in types, fwiw
I figured
wim
wim
@AndrasDeak is an error returning False ?
22:41
@sidnical process and thread id's perhaps?
@wim trick question? :P
wim
wim
rhetorical question :)
oh man, what happened to thereifixedit.com
not sure how official it is, cheezburger or not
23:00
1 hour ago, by Code-Apprentice
Can you yield from an async function? And will await just pick up where it left off like with next() on a normal generator?
and how do I send input to a async coroutine? I'm having difficulty wrapping my head around all this.
Hello - (people may respond with "cabbage", don't be alarmed, that also means "hello" in this room)
...and what a Unicode-laden name you have!
@Ḿűỻịgǻṇạcểơửṩᛗ cabbage
23:58
Cabbage. Rhubarb. Cabbage. Rhubarb. Cabbage. Rhubarb. (translated to salad from Tralfamadorian)

« first day (3352 days earlier)      last day (1820 days later) »