« first day (3850 days earlier)      last day (1105 days later) » 

12:36 AM
@CoolCloud thanks for making my day :D
 
12:46 AM
I wonder who upvoted though
 
wow, I did not notice that, and I just noticed the date of the question as well, probably OP asked his friends, I dont really see anyone visiting that question soon after they posted
 
Probably :p
 
it might be wrong but they still took effort to check the source, "go to line number 2625" shows some research
but I guess I should stop talking about something that has already brought to a close here, just caught my eye, my bad chat :)
 
I literally went and did some research to make sure I was not wrong, as OP seemed confident :p
I don't downvote answers, because there is at least some effort somewhere, unless its really bad or arrogant or something related to Modi.
 
I have been on a downvote spree, lately, I called out two OP's for double posting this week and one OP has both their questions closed now :/
 
12:54 AM
evil :p
 
in my defense I can not actually vote, need 200 ish rep for 3k, I just leave a comment, so its not all my evil ;)
 
1:13 AM
I could upvote 30 times, that would probably ban me for the next few months lol
 
@NickAlexeev yes, it's called a list comprehension
Not an array: a list
 
@CoolCloud that would probably ban me more than you :p
I could go spam all should have been duped questions, but its not like I need 3k that bad
can anyone tell me, which is the best practice here, option 1 or option 2
# option 1
if cond1:
    foo()

elif cond2:
    foo()
    break

# option 2
if cond1 or cond2:
    foo()
    if cond2:
        break
I am also open for an option 3, if there is one
 
 
2 hours later…
3:36 AM
Anyone on that knows anything about multiprocessing?
 
4:11 AM
In Django, I have a "player" model that has an "attributes" model field. Is OneToOneField the best option for this?
obviously each player will have a unique set of attributes.
 
 
2 hours later…
6:17 AM
@qaispak I don't use Django but in Flask I'd build it as a one-to-many relationship. You say yourself that players have a "set" of attributes, so it can't be one-to-one?
 
 
1 hour later…
7:17 AM
Is there a clean way to get Bank Holidays that people use?
I've not gone through all of python-holidays yet but it seems like a tricky problem so I'm curious if others rely on it
 
7:42 AM
Not exactly clean.
I'd (and we do) keep a list of dates ourselves.
 
Thanks for that. I was doing a code review and noticed that my colleague has hard-coded them in until the end of 2022. My immediate thought was "well that's a time bomb that we'll all forget about" - I had enough trouble working around BST not being automated across a lot of units in the factory at my last job.
How do you keep the list? Is it a central github repo?
 
Nope. We have a file for each trading day. If there isn't a file, it wasn't a trading day.
We could track that in a database as well but that is the source of the logic.
 
Even for in the future?
That seems like it only works retrospectively?
 
We don't see the future, unfortunately
But seriously, we don't have much need to make sure holidays are nailed down into the future.
 
The more I think about it, I'm not sure we do too. But I think the code might blow up because our client won't have jobs for us to solve. I guess we just make the code more fault-tolerant but it's hard to distinguish between a bank holiday and a broken data feed without knowing specifically if it's a national holiday :/
 
 
2 hours later…
9:38 AM
if datetime.now() > end_of_hardcode:
    raise NotImplementedError('Run out of time')
And assert that the last holiday is within 6 months of end_of_hardcode otherwise they'll just push that out to get rid of the warning :P
 
9:50 AM
I like it; probably the most pragmatic approach. I think I've wandered too far into complexity. Thanks :)
 
 
1 hour later…
10:52 AM
In the absence of a better solution, you could at least make the y2.022 problem harder to forget by emitting a warning when you approach the end of the list, and/or raise an exception when you pass the end
Use your best judgment to decide whether "we're crashing consistently in production because of a missing holiday list" is a preferable catastrophe to "we just noticed that we've been producing junk data for a month"
Oops these tired eyes of mine missed Andras' suggestion. Oh well, independent verification means the idea is double good
 
11:10 AM
:)
 
a more realistic approach is a warning 6 months ahead, with an assertion that breaks tests on the deadline (but keeps prod going)
 
11:21 AM
So what Kevin said, but moving the crash to CI
 
When there's one month left, it disables the office coffee maker, to incentivize prompt maintenance
 
Use case for HTTP 418
 
A criminally underused protocol
 
Very much in-line with my favourite workplace sign - "The beatings will continue until morale improves", just slightly more practical
Thanks for the input from both of you. I'll make sure the app shouts a lot
And piR, sorry
 
user13774796
I'm new here, what is this chat room all about?
 
11:36 AM
Welcome :) We have a community site here and there's more info here
 
This new feature I'm implementing has taken me into 100-layer-deep callback hell, and I'm trying to decide whether I should make the easiest possible modification and flee, or refactor this into a saner form
 
Does it recursively reticulate splines?
 
Nah, I don't do spline work on the weekends. This is a userscript that adds a hundred images to the end of a web page. I don't want the N+1th image to start loading until the Nth image finishes loading, so the function createImage(n) binds a callback for createImage(n+1) to the image's onload attribute.
It works, but I'm annoyed that the structure is so wonky for what is essentially a for loop
Maybe I can do something more linear if I use async... Not my strongest subject I'm afraid
 
11:53 AM
Are you sure it's not limited by bandwidth first?
 
v0.1 did use a regular for loop, and all the images loaded simultaneously. It took about thirty seconds. Not an unusable experience, but it would certainly annoy the user some amount. (It's me, I'm the user)
The callback hell version loads the first couple of images near-instantly, and the rest load in fast enough that they're present by the time I scroll down far enough to see them
In other words I'm satisfied with the performance of my ugly code, and would now like to make it less ugly
 
Interesting. I have this (though a much smaller issue) on my website loading a single image. It's painfully slow and I'm not sure what I did wrong with static resources
What are the callbacks actually doing?
 
@Kevin This seems to work:
const promise = new Promise((resolve) => {img.onload = resolve});
document.body.appendChild(img);
await promise;
 
@Aran-Fey now I'm confused about the browser's default behaviour
 
Here is my current working code. The script is designed for a message board I frequent, where users often post images, which appear by default as postage-stamp sized thumbnails that you have to click to expand. I'm lazy, so I want to see all the expanded images at once.
 
12:06 PM
Actually, never mind. My code has a race condition, and a really bad one at that
 
Half the code is just inserting the "expand all images after this point" button into each message box. The gritty callback stuff starts at function buttonClicked(postid)
My v0.1 code also had a race condition, because img.src = a; img.onload = b might never call b, if the image loads before the second assignment statement executes.
Luckily it's an easy fix, just switch the order of the assignments
Maybe I could do something like, create a generator of all the urls, and set every image's onload to setattr(this_image.nextSibling, "src", next(url_generator))
 
Kinda surprised JS's Promises make this so difficult. This would be super easy in python
 
Any design that doesn't require me to touch an actual index is automatically superior to this one
 
user13774796
Can we talk about Python libraries and frameworks here or just Python?
 
Libraries and frameworks are fine topics yes
 
12:14 PM
Evidently we can even talk about JS here, so python libraries and frameworks are totally fine
I can think of a few ways to circumvent the race condition with the Promise, but they're all gross...
 
As always, whenever I veer horribly off topic, I encourage everybody to prioritize any on-topic conversations that are also going on
I never want my JS brainstorming to drown out, say, Python library and framework chat
I was trying to keep it language agnostic but I guess the cracks started to show around "userscript" -_-
 
Ok, I'm officially a moron.
const promise = new Promise((resolve) => {
    img.onload = resolve;
    document.body.appendChild(img);
});
await promise;
Just do ^ that.
 
Hmm intriguing
 
user13774796
JavaScript is just a really bad language. It looks terrible and it does so many things to avoid crashes, and you have to write workarounds around problems that the language has. But there's no alternative usually, so people just have to go with it.
 
Javascript is terrible and I love it, it is my ugly little baby
 
user13774796
12:25 PM
Is there any way to make Python faster? I hate waiting for my code to print "hello, world"
 
Rule of thumb: if there was a way to make a language faster in the general case, then the language's devs would have made that the default behavior already
 
How many microseconds are you waiting for your code to say "hello" to you?
 
FWIW, printing "hello world" should be roughly equally fast in any language
 
sounds like you're using pycharm. ;)
 
If you want to trade flexibility for speed, consider Cython. If you want to do fast mathematics on big rectangular arrays of numbers, consider numpy and/or pandas. If you want to optimize a particular function as much as you can, write it in C and tie it into your script with the C API.
 
user13774796
12:28 PM
Hmm... Right!
 
user13774796
@ParitoshSingh I am T_T
 
But yeah, literally print("Hello, world!") should be pretty fast already
 
pycharm definitely has some overhead in setup and load times. It has its benefits and it's downsides. But yeah, make sure you identify the correct bottlenecks when things feel too slow. considering a print hello world, that's literally nothing python has to do for a simple print.
So i suspect your perceived slowdown must be coming from elsewhere, and the IDE is my first culprit of choice
 
To be fair Python does have a certain amount of unavoidable startup time even if you're running it straight from the OS' command prompt
 
For sure, but nothing compared to having to bleh compile a script separately
 
12:32 PM
Yeah we're plainly superior to all of those languages that make .exe files B-)
 
user13774796
That's for sure
 
Sure, one could argue about speeds once compiled, but i dare say i've now formed the opinion that most times, the language is fast enough for all practical needs. Thus, any further speed comparisons is not really beneficial, unless your use case needs the extra speed.
In that sense, python firmly falls in the "fast enough" category.
 
Yep, I've been satisfied with its speed for 99% of my personal projects.
It could stand to be about a hundred times faster when it's executing my KevinScript parser, but that's mostly my fault for sticking with the first approach that worked for about half a dozen easily optimizable algorithms
 
In any case @Adith you've not actually described the problem you're facing
 
I could probably get a nice boost just by laying out my data structures with cache-friendliness in mind
I'll put that on the todo list for the v1.∞ release
 
user13774796
12:47 PM
What is KevinScript?
 
KevinScript (abbreviated "KS") is a programming language inspired by Python and Javascript.. It's a real language that I wrote mostly because I thought it would be funny
I haven't made any updates in years but it continues to be a useful basis for thought experiments relating to language design problems both practical and philosophical
 
1:06 PM
@Kevin I have to downloaded way back, just waiting for the right time to try it
 
Take your time, I'm not too interested in getting my user count up ;-)
Not until I sneak in a bitcoin miner in the next version, at least
 
@Kevin Anyone here into bitcoins?
I'm curious why the environmentalists are not coming against it as it takes a lot of electricity?
 
too many things to go against first. get in line!
 
Hefty job
 
@CoolCloud I'm pretty sure they are, or I've just imagined a lot of news articles
 
1:20 PM
@Kevin You are still on top there, gonna be a long ride for me to beat that score(assuming you don't start answering again) stackoverflow.com/tags/tkinter/topusers
@roganjosh I mean whatever it is, there is going to be one more fights against it. Good or bad.
 
I have no idea what that means or what stance you're taking. If you have a conviction or a view on something, at least stick by it
 
I've definitely seen multiple people on twitter saying bitcoin should be outlawed as long as it consumes as much electricity as it does
 
Otherwise you're saying "stuff happens". I guess that's true, but not really report-worthy :)
 
My opinion is, wasting lots of electricity for imaginary points is bad, but there is lower-hanging fruit than this we can go after first
 
I meant on a general basis. If we found out a way to make money(bitcoins), some people(environmentalists) are going to come against it. Even with AI, many people oppose it.
 
1:24 PM
@CoolCloud Our battle will be legendary
 
@Kevin You are going to hang in there for ATLEAST another 1 or 2 years with domination.
 
Perhaps some environmentalists are only protesting because they've got sour grapes about not getting rich off of bitcoin, but my anecdata points towards most of them having more sincere motives
 
I hope though. Because nowadays its double faced people around, so...
 
Yeah, insincere haters can show up anywhere, although I suspect they appear to be a larger population than they are simply because they're really loud
 
And selectively loud since "microphones" can be adjusted to measure, depending on what the hot topic is
 
1:29 PM
In any case I lean towards consequentialism, so if haters facilitate a noble goal in pursuit of their own selfish ends, then it's still a win
 
@Kevin Hmmmmm I tend to also look at the motive and then the consequence. Dont know if there is any fancy word for this :p
 
If the Great Barrier Reef springs back to life because narcissists on twitter were promoting awareness of it to look woke, I'm happy to let them have their clout
 
Any downsides of using eval? Like for exec, we can actually say exec('import os; os.....') which can be misused. So anything like that for eval?
Like any naughty expressions in python? :p
 
Basically everything
 
Yes, eval is just as powerful as exec thanks (in part) to __import__()
 
1:41 PM
Uhm any example?
 
>>> eval("__import__('os').system('echo you are now hacked')")
you are now hacked
 
Damn.
I was actually thinking of using eval() on a calculator to parse their mathematical expression and wondering why the no-one has followed this easy method. Lol
 
I have personally broken multiple "eval prisons" that purport to keep the user from doing naughty things. Some of them had dozens of hours of thought put into them, and passed scrutiny for years.
 
@CoolCloud sympy?
 
1:49 PM
Never heard of it, seems cool though. Better than the traditional method of storing the previous value and then adding it with the recent value, TBH.
 
sympy is quite good for evaluating math. You could also use ast.parse to generate an expression's syntax tree, and evaluate it yourself as you iterate over it. This is safer than eval because you can simply not implement behavior for function calls or attribute accesses etc.
If you're thinking "but I want my user to be able to execute arbitrary functions, in case they want to use math.sin or whatever. Can't I just make a blacklist of bad functions?", you're doomed
 
@Kevin Thankfully I am not
 
@CoolCloud Well that would depend on what the loop does. If you think I'm putting sympy into my solver loops any time soon, you're dead wrong and I don't know why you'd want to do that
 
I mean would it be simple to just evaluate something like '2+2*3+4/4' using sympy? Then it would be really helpful.
 
It can probably help with that. Where did the "storing the previous value" bit come from?
 
1:55 PM
It was from a tkinter tutorial I used to follow. Many people on SO have been asking question related to those too. A kind of not thoughtful method I guess. youtube.com/watch?v=XhCfsuMyhXo
 
anyways yes, eval for calculator is one of the best beginner traps that exist
 
@ParitoshSingh True that
Because I was really intrigued by this instagram.com/p/CNO2SnIgSj9/?utm_source=ig_web_copy_link till I found out now :p
 
"You have to learn every single concept!"
What fresh garbage is this?
 
@roganjosh When was that(time stamp)?
 
It's right there on the link you just gave. I don't have an account so apparently I can't tell you
 
2:02 PM
@roganjosh That is the tutorial from which this method was found
 
@CoolCloud here is a quick framework for four-function arithmetic evaluation. 99.999% guaranteed to not let you get hacked
 
that instagram link looks like it's "sign up" walled
 
The last 0.001 is scenarios like "the bad guys go to your house and physically take your computer". I can't help you with that one.
 
@CoolCloud and I'm saying it's likely to be garbage based on that stupid picture that I found
 
@ParitoshSingh I mean instagram posts are like that, if you dont sign in.
@Kevin Sad
 
2:05 PM
"You don't have to diet to get lean. Here's my 5 minute youtube diatribe advert"
 
Alexa play despacito
 
@roganjosh That is some literal hate :P Which picture?
@Kevin Now playing: Despacito
 
The one that literally says "you have to learn every single concept!". I don't think I've been unclear on that
 
@roganjosh Youtube ads be hitting hard though.
 
The hackers, still looting your living room: "ooh, this is my summer jam"
I also don't have an instagram account, but I don't see a picture on that page saying "you have to learn every single concept". Maybe everyone gets a different randomly generated selection of thumbnails.
In any case. Learning every concept is... Probably impossible for a human with an ordinary lifespan.
 
2:09 PM
@Kevin Me, calmly sleeping without knowing that my house is being looted by 4 men because I used eval :(
@Kevin Literally, yeah
@Kevin I am still not sure if he is referring to youtube video or the instagram post.
 
@CoolCloud for safer alternatives to eval() check out ast.literal_eval() and potentially json.loads()
 
Me neither, but I trust that his eyes do not deceive him, so I'm not inclined to investigate further
I'll take a page out of Ratatouille and say: don't learn every concept, but be willing to learn any concept
 
@Kevin I literally don't know why, but I was expecting you to come up with something like this :p
 
"sentiment analysis? Ehh, I am a humble csv parser writer, I can't do AI" -- wrong! Don't let your dreams be dreams
 
@JonSG Hmmmm I'll take a look there
 
2:12 PM
ast.literal_eval used to be able to do a little bit of arithmetic, but I think they tightened it up recently
 
If I could work out how to save a screenshot from a Mac then I'd post it. Less easy than it seems, apparently (MS Paint, where are you?). In any case, I think it's just clickbait
 
Windows wins again !
@roganjosh I thought you had a windows 7? or was it someone else, when you shared a screenshot of your browser with infinite tabs open.
 
I'm on my work laptop which is a Mac. My own laptop is Windows 7
I takes a couple of minutes to acclimatise to the new keyboard layout if I swap
 
Why does everyone like windows 7 🤔 @Kevin @roganjosh
Not everyone :P. you guys I mean.
 
Because it makes sense to me and I've been using it for like 20 years?
 
2:15 PM
That is older than me....damn
 
Many of my habits are explained by the umbrella of "brain problems??"
 
I have 16 GB ram and this lap still lags at time 😬 Maybe absence of SSD might explain it.
 
I grew up with Windows, back from Windows 3.1
 
o.o what even is windows 3
 
Typically speaking, I grew up with windows too. Windows XP
Seems like windows used to have version naming issues (3.1)
 
2:17 PM
@CoolCloud here is a post about doing simple maths with ast.literal_eval(): stackoverflow.com/questions/20748202/…
 
The first windows i remember is 95. maybe there were ones before that that i used, but i don't recall them anymore.
 
@JonSG Kay sure, I will try it out
@ParitoshSingh I remember XP, some years back I realized there used to be prior versions, lol
 
@ParitoshSingh Pepperidge Farm Wikipedia Remembers
 
XP was great, and windows stuck with it for a while
 
real OG <3
 
2:33 PM
Regarding JonSG's link, I believe poke's answer is out of date. As of 3.7.0a4, "Addition and subtraction of arbitrary numbers no longer allowed" in ast.literal_eval.
His code block looks fine to me though, since it's quite similar to the one I wrote and tested half an hour ago.
It looks like it got reverted back to the 2.7 behavior of only parsing additions/subtractions that have a complex constant(?) on the RHS: github.com/python/cpython/blob/…
Reading bugs.python.org/issue31778, the official reasoning seems to be that allowing "1+1" in the first place was an undocumented and unjustified patch, and it's correct to reject it unless rhettinger comes along and explains his rationale
 
 
2 hours later…
5:05 PM
@CoolCloud In which case I started programming over 30 years before you were born. Maybe before your parents were born ...
 
@holdenweb That is a very very long time, but not before parents though.
Do you get bored? being in the same field?
 
@CoolCloud Browser tabs can really eat memory; last time I quit Chrome it was using 7GB of memory. I'm trying to be a bit more conservative with the tabs now ...
@CoolCloud Nope. I stopped programming professionally (I believe ...) at the start of this year, having started in March, 1967 (in Algol 60).'
 
Wow
 
Still diong it for fun, though, and still enjoy hanging in this room shooting the Python breeze. Good people live here.
 
A very interesting field this is. New stuff, new areas.
 
5:11 PM
Always. Something new to learn whenever you like!
I used Windows 2.0 on an 8086-based system about twenty years into my career. It ran on DOS. Mostly I just used DOS, as Windows 2 was painfully slow.
 
And you were able to use the first windows and the last windows I guess?
 
5:38 PM
@CoolCloud Mostly nostalgia for me. I used to use windows 7 on the old school computers, and it actually made sense. It had Command Prompt by default unlike this new... ShowerPell? PowerShell? I don't know.
 
@10Rep Wait what? Windows 10 don't have cmd preinstalled?
 
@CoolCloud It's there, but you have to go and enable it in settings in order to use it.
 
@10Rep Hmmm? I did not have to do anything as such. Don't know
 
sounds like a big ol XY
 
I think he's approaching the problem in a way that makes his life much more difficult than it needs to be. Who the heck needs a graphical dependency installer? And why does he want to do it in a terminal?
 
Hmmmm if OP is making an exe, then its already going to be bundled.
 
6:41 PM
@10Rep powershell. And I agree that it's less useful for the kind of things I want to do, but it has existed for quite a while, they just switched round the defaults
 
7:04 PM
@holdenweb I did quite a lot of research around this (more than I probably should) and the approach was basically "if the memory is there, take it". It'll expand to 80% of RAM if it exists, but it also should scale back if you have other stuff running. How well Chromium/Chome and the OS do this is an open question... but it won't be limited by you limiting tabs alone
At one point I found that pretty shocking, then I started having to use Docker and, well, top does not give a happy picture any more
 
7:16 PM
On the Docker side, I found an article that said "A common misconception is that setting the memory limit of Docker will actually limit its memory use, but this is not true. Run this:" I think that's one of my favourites, I'll try dig the article out
 
8:00 PM
Hey, I have a question on Pandas, I have a pandas dataframe with three columns: location, lat, lng. I have a function that can return a lat, lng for a given location. I need to replace data in the pandas dataframe where lat, lng is NaN. Anyone have an easy solution?
 
@Inthu replace with what? df.fillna is the easiest if it works for your use case.
 
@Andras replace with the results from the function
 
There can't be a result from a function with NaN other than a default
 
@Inthu So for each row where either lat or lng is nan, you want to call the function with the corresponding location and overwrite lat and lng?
 
@AndrasDeak Correct! But finding it difficult because lat, lng are two different columns
 
8:04 PM
@Inthu not that difficult, you can check where either column is nan and then apply a logical and on the columns
Does df[['lat', 'lng']].isna().any(axis=1) work in pandas? I always get errors with axes stuff.
 
Yes that works locations_df[locations_df.isnull().any(axis=1)]['location']
 
That would also check if the location is nan. Might be irrelevant on your data, just FYI.
feeding your function a nan could break something
Well, not a nan, because it's a string.
 
Oh yeah, I have cleaned that column before hand
 
If your df is huge it might also help if you're only checking 2 bool columns and not 3. But this is probably micro-optimization category.
Oh, and I'm not a pandas user so someone else might have better approaches :P This is the naive numpy approach.
 
I like the use of "naive" in that, when it's probably going to be fastest and the most informed :P
What does the function do?
 
8:10 PM
:D Agreed
Function returns a lat, lng
 
From what? You just said there were nan values
 
from the given location
that has a coressponding Nan
mask = locations_df[locations_df.isnull().any(axis=1)]['location']
But that applies to one column called dist and function only returns only one value
I need to apply two values and my function returns two
 
So your question is just how to apply a function to two columns and has nothing to do with lat/long?
 
Yeah :/ I only found this example now
 
If you're calling a custom function, you can forget vectorization btw. If you actually gave an MCVE then we might be able to reformulate the issue
 
8:15 PM
well if only 1% of the data is nan then it's still better to find those first
 
MCVE?
 
complete :P
 
it seems to me primarily that the fundamental question boils down to: how do i assign to two columns at once. In which case, i should mention that you can specify multiple columns to assign to at once on the LHS as well, using a list syntax. df[[col1, col2]] = list_of_tuples
 
I copy/pasted from the title to save keystrokes. I'd already just put "MCVE" into Google and found it as the top result, so I didn't want to invest too much more :)
 
8:20 PM
I'm surprised that the epic renaming of MCVE to MRE didn't suddenly solve our problems of users not providing one. I never would have guessed that.
Perhaps if we add two pixels to the size of the border around badge icons...
 
Can you pay me for 5 PhDs and a project lead? I'll get to the bottom of this in 3, maybe 4, years!
 
laurel
 
locations_df = pd.read_csv(path, usecols=["location", "lat", "lng"])
mask = locations_df[locations_df.isnull().any(axis=1)]['location']
locations_df[['lat','lng']] = locations_df[mask].apply(calculate_dist, axis=1)
                                               location        lat       lng
0                     Robinsons, Dungannon BT71 6EU, UK  54.531090 -6.715733
1                   R439, Garbally, Co. Offaly, Ireland  53.149881 -7.936189
2                            Milton Keynes MK17 8EW, UK  52.037171 -0.659877
3     Leeds Train Station, New Station Street, Leeds...  53.794964 -1.547369
4                                             Leeds, UK  53.800755 -1.549077
...                                                 ...        ...       ...
def calculate_dist(x):
    return -1, -2
 
Well that's silly, isn't it?
 
probably just for the sake of example
 
8:23 PM
good job on simplifying the function. that's the part i liked best
 
Example
LOL
 
If you don't know the lat, then you also don't know the long. But you can do an address search
 
couple issues stop this from being an mcve, which is primarily around us not having the file
 
nominatim can possibly help with filling in the locations
 
which could have been made nicer if you made a dummy dataframe that also showcased the issue with fewer rows for example. especially ones with nans in it
 
8:25 PM
df = 0/pd.DataFrame({'a': [0, 1, 2], 'b': [1, 0, 3]}) is the most minimalistic I could get earlier
it doesn't have a location column though ;)
 
By silly, I'm also talking about it in a domain-specific way, which happens to be in my field. You'd surely have to have sensible values coming out of the function call
 
@roganjosh my understanding is that the real function provides sensible values, and the original nans are not the result of this function.
 
@roganjosh im about 99% sure they have zero problems actually getting the lat and lon in their real function. their question starts from them wanting to assign the results back.
er, yeah what AD said
 
Of course if you have a universal latlonifier function then you might as well set it loose on all your data ;)
 
real function has values, the csv being read needs to be updated as it contains new data where some doesn't have the lat, lng
 
8:27 PM
I'm betting against both of you, but ok :)
 
@Inthu anyways, i see that you edited your assign statement, but it will still have issues because you need to be using the mask information on the LHS as well, if you only want to assign where it's NaN
 
Doesn't pandas error out when there's a size mismatch in an assignment?
 
yes
 
I hope it doesn't just fill it up with nans
 
pretty sure it does
 
8:28 PM
OK
 
@AndrasDeak although, i wouldnt have put this behaviour past them. :P
 
then there's the "setting values on a copy" warning :P
@ParitoshSingh same
 
@AndrasDeak That's just a "hello, old friend"
 
im going to go on a good faith assumption and assume that locations_df[mask].apply(calculate_dist, axis=1) this portion gives you the results you need. So then, locations_df.loc[mask, ['lat','lng']] = locations_df[mask].apply(calculate_dist, axis=1) Should do the trick. If it doesn't, i'd love for you to try making the MCVE again, with the minor changes i suggested. Primarily, give us code that lets us get a usable dataframe without any external files.
 
@ParitoshSingh don't you need [mask, 'location'] on the RHS?
 
8:35 PM
As for whether it actually gives you the results you need or not, i'd suggest breaking this into two steps, and first just assign and see the outputs of the calculation in a separate variable
 
the function only takes locations
 
@AndrasDeak tough to say, depends on how the function itself is written.
 
it can't take lat/lon because it's supposed to return those
 
@AndrasDeak it shouldn't take the lat/lon because it's supposed to return those, aye
 
Or not using apply and instead use a solver for the Haversine (presumably) function in a vectorized way
 
8:37 PM
Does the Haversine formula take addresses? :D
there has to be some API lookup in there
 
Then it needs to be nominatim. The question just isn't clear to me
 
@roganjosh I think the question is what Paritosh answered. "I have this function that returns two things when passed a third thing. I have a bunch of third things in a df and I need to replace their corresponding first and second things".
 
We have some function doing something and there's NaN values. Somehow lat/long and addresses are involved
 
If you plug in the lat/lon data from the dataframe snippet above into google maps you get the corresponding address back. So there's no Haversine, just standalone GPS coordinates.
 
But you can't call on Google maps like that without an account. I have other ways of doing stuff in this area but I'm getting frustrated without a solid example
 
8:43 PM
@roganjosh I'm not talking about the API. I literally just put the first lat/lon pair into google maps and I got the first address. I'm just saying that the data in the df is "where is it?" rather than something closer to your routing background :)
 
cbg
 
bah, sorry for the pings
So I'm saying that fundamentally the details of the function and the lat/lon are red herrings. There are nans in a 3-column dataframe and they have to be replaced based on the first column using a single-arg function.
 
It was almost melodic :P You missed the main beats of my current song on youtube, though
 
I agree the details of the function matter because it might be possible to vectorize it instead, but in this case I doubt it. Because of the whole "address a strings" thing.
Unless every address can be queried at once using some API, in which case the loop is pushed over to the API's side.
But that's a different question and needs very specific information about the API at hand. And I don't think Inthu wants us to go there.
 
Even if you can't vectorize it, I have all the necessary tools to convert postcodes to lat/longs or query OSRM or... well just give me an MCVE
If it's purely about assigning to multiple columns, we have a canonical for that, too
 
9:11 PM
Anyone here with some experience of signal module?
Or anyone have any idea why signal.SIGALRM returns AttrError on a PyCharm IDE and not repl.it
idk why that's happening, but I'm trying to help someone and this weird thing happened ^^ 😅
 
Have you had a look at the docs?
 
yes
oh, only available on Unix
 
bingo
 
damn, is there a workaround?
 
Depends on what you're trying to use it for
 
9:28 PM
Can I link the question I'm trying to answer it for?
 
Sure
 
0
Q: Time limit fix and randomization

MadeleineI'm trying to make python run a short multiple choice quiz where each question is randomized each time the quiz is taken and there is a time limit for each question. I have a time limit, but it doesn't seem to work. At least, not until I give an answer. I'm also having trouble figure out how the ...

 
Ah, user input with timeout. Gets asked all the time, and there's never a good answer for it
 
I searched it up and signal was the only thing I found
 
80% serious suggestion: Write a GUI instead
 
9:34 PM
lol
 

« first day (3850 days earlier)      last day (1105 days later) »