« first day (3077 days earlier)      last day (1854 days later) » 
00:00 - 22:0022:00 - 00:00

10:01 PM
Ok, so I have a question, in which use case is it better to use itertools.tee(iter) instead of a simple list(iter) when dealing with several iterator consumers.
 
how does list(iter) do the same thing?
 
I think they mean reusing that list later in multiple places
 
wim
if it's not many items use list(iter)
 
Yes, the list will be used instead of iterators in the case where you don't use tee
 
wim
10:03 PM
and you can only effectively use tee if the consumers are consuming at approximately equal rates, which is hard to guarantee in general
 
I'd expect tee to be relevant when you can't hold all of it in memory, like with an infinite iterator
 
@AndrasDeak now I know why I never get some of the high-brow humour here. My brows aren't high enough.
 
wim
if you use tee, consume one, consume the other, then you may as well have just used list in the first place
 
yeah infinite iterators, that's a good example
 
I wonder, does tee use a deque under the hood so that it can throw away the prefix as it becomes obsolete?
 
10:06 PM
@AndrasDeak The documentation shows a fake implementation of it that uses deque
 
I guess that's close enough
bah, I clicked a python 2 docs link
 
The docs say it uses a FIFO queue (of some unspecified sort)
 
thanks, that's a perfectly satisfactory answer on my level of understanding
 
:D
 
Ah, yeah, the fake implementation has a deque for each iterator which makes it sort of irrelevant for my question. If you always yield d.popleft() the prefix items naturally drop out.
 
wim
10:17 PM
I wonder if it the FIFO queue (of some unspecified sort) eventually goes to the same C code that is _collections.deque
 
it should, unless it's performance crtical to throw away functionality from the latter
 
Doesn't look like it reuses any code from collections: github.com/python/cpython/blob/…
 
@AndrasDeak Sorry, forgot I read this in the morning while dashing. Yes, I think that probably is the interpretation. As an opening statement to that section I guess I hadn't really framed the context correctly while reading. Thanks.
 
good on you for being dashing in the morning
itertools is black magic
 
<robotic voice> "Fabulisation complete". Technology is awesome these days, makes mornings much easier.
 
where's the _collections.deque connection?
 
wim
there isn't one. this is a linked list
 
ah
Singly? I only see nextlink
 
wim
yes compare deque is a doubly linked list github.com/python/cpython/blob/v3.7.2/Modules/…
both from raymond (!)
 
Also, deque uses blocks, looks like tee does not.
 
10:36 PM
@wim ah, good, good
 
@AndrasDeak heh, nice one
 
wim
implementation detail changed in 2003 github.com/python/cpython/commit/…
 
@Aran-Fey Please don't encourage him
 
I thought we liked bad puns here
maybe that one was too good
 
mmm not exactly a pun
 
10:39 PM
Technically it was me that made the pun and he just forced everyone else to read it in that context. I'm asking you not to encourage him because I really don't wanna have to go for royalties
 
@roganjosh not a fan of unrestrictive licenses eh?
 
Don't forget Stack Overflow uses CC-by-SA
 
@roganjosh EU will protect me from outside threats :P :(
 
Eu bullies strike again :/
A quick aside. Did anyone else hear TM's announcement tonight? I've heard it roughly 1 and a half times (the live feed went on to do a snippet) and actually it felt like I was being read a bedtime story
The tone and animation. It reminded me of my mum reading the Magic Faraway Tree to me when I was a kid
 
wim
TMI
 
10:43 PM
TLI, it contained nothing of substance
 
I did listen to her but I don't know your mum
 
@roganjosh TM?
 
theresa may presumably?
 
Theresa May
 
wim
she may presumably what?
 
10:45 PM
lmao
ok, that was a pun
 
@wim "Theresa May?" stands alone as a book title because who knows what's gonna happen
 
10:59 PM
@roganjosh this may (No pun intended) be more trouble than it's worth.
 
Well it leaves the scope fantastically open. If the author gets writers' block half way through discussing what she may do, they could go into a biography
 
11:15 PM
Mmm, after reading a pandas answer from a data analyst at a major bank, I think I'm close to a breakthrough in financial crashes...
 
it's a trap do deceive the competition...
 
It's actually a little worrying. The misunderstanding is re: in-place modifications to dataframes. Because print(my_new_object) is showing the right output, all is good and solved.
 
it probably gets much much worse than that
 
@roganjosh cant wait until pandas completely deprecates in-place things.
 
ideally an industry built on faulty parts might still function due to safeguards being in place
 
11:24 PM
@AlexanderReynolds I sit on the fence tbh on that one. I am ashamed to say that I misunderstood groupby for over a year and assumed the result had to be assigned back to a name
 
I also hate the groupby interface and documentation.
 
It didn't even occur to me that I could use it without new_df = df.groupby()...reset_index()
 
I think I just kinda hate much of pandas tbh.
(note that I say this as someone who uses it every day)
 
so guys, what is the most common alternative to using a global variable without needing to drag a variable through mulitple layers of functions
 
@Skyler OOP
 
11:27 PM
I also use it every day and I find it pretty stressful for maybe 10% of my workload that ends up taking 95% of my time. Totally throws off the 80/20 balance.
 
@roganjosh Yes exactly.
 
@AlexanderReynolds you don't need to pass the object into a function for it to still be available in the scope right
 
@Skyler Well in that case the object is still a global object. I mean that attributes on an object are "global" in the scope of the object. So if you use methods instead of functions, everything can access that variable, just like global functions accessing global vars
 
@Skyler note that "using a global name" is much less bad than "using the global keyword to modify a global name"
 
@AndrasDeak ++, there is a distinction on a global variable as opposed to a global constant/value
 
11:29 PM
@Skyler What's more important is whether the value changes
 
@AlexanderReynolds weeeell, there are no global constants in python :P
 
@AndrasDeak well yes and they're all variables anyways
 
People often refer to names as "variables" but a lot don't actually change. MY_GLOBAL = 2 is generally fine.
 
@AndrasDeak are you telling me that putting the variable name in all caps doesnt change the way it works?!
 
But if you're accessing a global name surprises only happen locally. If you rebind a global name using the global keyword then you're causing surprises elsewhere. And there's the sneaky middle-ground of mutating a global name without referring to it as global x
 
11:32 PM
note: this is also why I like having a namespace for constants in a project.
(but then I'm never quite sure if they should have caps for the constants....)
 
Yeah but that's module level, not project/application level.
e.g.: math.pi, not math.PI
 
If you choose to define them in a module of their own, you couldn't have them capitalised in that module and then use them in lowercase elsewhere after you import your constants.py module elsewhere
So they should be capitalised IMO
 
Yes, but they commonly aren't, even in the stdlib as above.
another e.g., the sys module has some lowercase constants/flags
 
1
Q: Why math.pi and math.e constants are written in lowercase in Python?

TrimaxIn most Python modules the constants are written in uppercase, i.e.: datetime module: datetime.MINYEAR datetime.MINYEAR locale module: locale.LC_MONETARY locale.LC_TIME locale.DAY_1 os module: os.PRIO_PGRP os.PRIO_USER But in the math module, the only 2 constants that has in it are ...

 
11:46 PM
I mean I'm not arguing that they should be lowercase, anyways. I do keep them capped, but it feels like I'm calling a class constant every time when I namespace them, which is a little weird. I'm not consistent on using the namespace tho, sometimes I just import the constants in directly.
 
I wasn't suggesting you were, but I think that answer explains the discrepancy you were showing
 
yea
I guess I'm not sure if it's fair to call sys.base_prefix or os.path.sep or pathlib.os.sep constants though
so...probably safe to say true package constants are capped unless specific/historical reasons
 
And since you're writing the code now, there's no reason to introduce the situation where you have to maintain the discrepancy :)
 
<sigh> more serial downvoting. This time 3 answers in order of their votes. We'll see how smart the automated detector is because this kinda thing got through last time
 
11:54 PM
it will probably get reverted
 
I hope it looks for patterns like that
 
if it's there after 3 AM UTC flag it
 
The downvoter obviously has profile answers listed in order of votes, and it's back-to-back
 
Hey guys, anybody work with strings in numpy, im interested in learning more about its use case, performance, etc.
 
Not that I'm saying it's bad to use it but...numpy, not strpy :O
 
11:56 PM
@Skyler Is this completely open-ended or do you have a use-case in mind?
 
ultimately I've got very large amounts of text data I'm going to be exploring with a variety of ML algorithms
but I'm interested in sandboxing with it for a bit
 
do you have any guarantees about said text data?
Numpy stores strings as fixed-width arrays
so having a high variation on string size and such isn't particularly efficient space-wise
AFAIK
 
The string size will have to accommodate the longest string
 
For now I can limit my selections to a specific length since I have so much data already available. I'm currently writing things to a sql database so I could have something like a string buffer of a max length and then I just work piecemeal.
 
11:59 PM
So, no, it will allocate more memory than is needed for the smaller strings. But I don't think Python lists will do a better job memory-wise (could be wrong)
 
In particular if it's all uniform it's pretty breezy to use.
 
Another option is I can batch by response length so at a particular batch things are prety uniform in size
 
00:00 - 22:0022:00 - 00:00

« first day (3077 days earlier)      last day (1854 days later) »