« first day (3079 days earlier)      last day (1870 days later) » 

5:04 PM
morning cabbage
 
hey guys, looking at hackerrank, i need to print out an average of numbers inputted to 2dp
 
> Even Jon Skeet cannot parse HTML using regular expressions.
 
but my answer is 51.0 and i am failing the tests. i have tried round(a,2) but it still outputs to 51.0
i do i force it to spit out 51.00?
 
its related to string formatting
idr the exact way to write decimal precision from memory. something like .2f?
 
5:07 PM
but its not a string
 
I have no reason to suspect that 51.0 is less valid than 51.00
 
>>> x = 51.0
>>> print("{:0.2f}".format(x))
51.00
 
exactly. non-strings dont get random zeroes at the end. So.. :)
 
@ParitoshSingh you nailed it
 
sweet
 
5:09 PM
You can't tell a float "you must have two digits after your decimal point" because the number of digits after the decimal point is a fact about its textual representation, and floats are not responsible for their own textual representation
 
im failing the other test for having the wrong answer lol
 
Which is more along the lines I was expecting rather than floating point error
 
I'm familiar with that post about parsing HTML with regex, but this is the first time that I read the whole thing through....such greatness
 
There isn't anything we can do unless you give representative example and - doesn't it defeat the whole point if we solve it?
 
@Code-Apprentice haha yep, its something else isnt it.
 
5:24 PM
seriously it is penalising me for 26.5 instead of 26.50
 
yah, it's pretty good. I have no idea how someone comes up with something like that...
 
lol
i guess they REALLY want you to learn string formatting perhaps?
 
(about string formatting)
 
end users
 
Oops, try to keep language PG-13ish
The HackerRank question writers give a darn about string formatting because it's easier to verify an answer is correct if you only have to check against one literal value
It's more work for them to confirm that 26.5 is correct and 26.50 is correct and 26.500 is correct, etc etc
 
5:28 PM
sorry guys about the swearing
 
It happens :-)
 
no worries. keep the rules in mind, we have people who keep this chat open at work and stuff too
so cant be too careful.
 
ok
 
One of the reasons I don't participate much in online challenges is because I can't stand overly-picky answer checkers
 
i need to practice these hackerrank style questions
 
5:30 PM
I dont think a person should be penalized for how they represent a correct answer, unless that itself is the point of the lesson.
That just seems counter productive really.
 
hackerrank questions all seem really fiddly
 
One billion quatloo penalty to HackerRank for not having a framework in place that allows problem authors to specify "the answer to this question is 26.5, but accept any output that resembles a float literal that would compare equal to 26.5"
 
quatloo penalty ?
 
Joke explanation: a quatloo is an imaginary unit of currency that I use to reward the virtuous, or to punish the unjust
 
It's the currency of our room
 
5:32 PM
HackerRank has annoyed me, so I have penalized them.
 
correction: Kevin's currency
 
is anyone here good at hackerrank questions?
 
we use it somewhat too :-p
 
I completed all the "hard" Python questions in twenty minutes, so I guess I am.
 
@Permian only if they want to be, and i dont think many people are inclined to do them here. A lot of folks here have an insane amount of experience with coding every day so.
 
5:35 PM
@Kevin what do you do all day?
 
Web development.
 
@ParitoshSingh i dont think every day coding experience prepares you for it though. these questions arent that good
 
Also, loitering in here
 
@Kevin 20 minutes? all of them?
 
5:37 PM
@Permian Well, its all programming in general. After you're comfortable with syntax, programming is just about problem solving
 
@Permian There are only three of them, so it didn't take long.
 
fair
 
And i believe the verdict was, 2 of them were only tricky if you didn't know about certain constructs? iirc
 
2 of them were actually regex questions, and 1 is trivial if you've read the documentation for itertools
 
i never used regex in my job
or maybe i did like once
and i just looked up the answer for that case
which is how i do all programming
 
5:39 PM
Nothing wrong with copy-paste as long as it's actually read-understand-copy-paste
 
yes i do that
 
recbg
 
m8_
Afternoon! Got a quick question...I have a dataframe of mainly floats, but also some strings. I am trying to simply remove the strings. I've tried df['colA'].replace('string', '') but it doesn't change the dataframe at all. Any ideas?
 
'string' tries to search for the literal string
 
5:44 PM
@Kevin i never itertools before
 
itertools contains many fun and useful tools. My favorite is groupby.
 
whats the point? python is slow
 
m8_
@ParitoshSingh, how can I remove the string then?
 
If you're saying "What's the point of Python when it's so slow?", you are free to use a different language if you don't like it. If you're saying "What's the point of itertools if Python is slow whether you use itertools or not?", not all libraries exist for the sole purpose of making things faster.
 
m8_
nevermind, I got it...brain fart!
 
5:54 PM
@Kevin "understand" is subjective...and has multiple levels
 
You better grok that code if you're going to run it in production
 
@m8_ nifty. had to step away for a bit. Just as well, because i actually dont know off hand how to remove rows with pandas on condition. or..
nvm, i guess i figured out a way while typing that sentence
Hm. im not sure what to say to this guy
 
"What's the point of itertools if Python is slow whether you use itertools or not? this
@Kevin
 
you can edit/delete messages for two minutes in chat
 
groupby doesn't make your code faster, it makes it shorter. What would ordinary take ten lines of code instead takes one.
 
6:01 PM
and please loop over the Cartesian product of range(10000) x range(10000) x range(10000) for me
 
And for that matter, i ask. Why do you say python is slow?
 
these are genuine questions
and you learn by asking questions
@ParitoshSingh GIL
 
And how does the "gil" matter here?
 
Python is kind of slow. However, I refute the implication that speed is always important.
 
@ParitoshSingh single threaded code
@Kevin RUST!!!
 
6:03 PM
My GUI does not need to run at a zillion petaflops a second. Anything beyond 60 fps is overkill.
 
but you are a web dev
 
I live a double life. My work projects are all web pages and none of them use Python. My personal projects are all Python and none of them are web pages.
 
haha
 
If the code is single threaded, then the gil doesn't come into the picture.
 
@Kevin python is the bottom of the list?? so relativeily slower than others
 
6:06 PM
@Permian a much more accurate statement. Python is slow in comparison.
 
You don't need to look at the language's relative position of the list to guess how much slower it is than the others. The "X" column outright tells you how slow it is: 143 times slower than the fastest submission.
 
But the language itself is fast enough for most tasks. The blanket statement "python is slow" is misleading at best.
 
my point was that if speed was important, why bother with itertools and just use something else
 
What "something else" do you have in mind?
 
java
 
6:08 PM
It's not as if there's a fast_itertools module with a fast_groupby function you could be using instead. If you need groupby's functionality, use groupby. If you don't need it, don't use it.
 
c++
 
It's fine to say "why not use these faster languages?", I just don't understand why you're saying it specifically in the context of a conversation about itertools.
If you're saying "Python on its own is fine, but once you discover that you need itertools, you should switch to java or c++ instead", that seems like a weirdly specific standard. Oddly specific especially since you've never used itertools before
Perhaps you're saying "Python is good enough for simple tasks, but once you have to import anything, you've reached a threshold of complexity where you should switch to using a faster language", which is a coherent opinion, although I don't agree with it
 
tests are awesome
 
wim
6:45 PM
C++ is slow to write
and slow to debug
 
tests are awesome : you can even make a living at it
 
@Kevin import fast
(it exists but doesn't actually make python faster)
 
user521945
I find that my computer is fast and my software rarely needs to be.
 
My time is valuable, my computer's time isn't
 
user521945
6:54 PM
If I'm changing something for the purpose of speed it's far more likely that I'm thinking about it incorrectly, rather than any form of optimization being necessary or worthwhile.
 
user521945
@Kevin Cupcakes in the break room.
 
FWIW I know that BP (British Petroleum) works with a logistics system that can make 10,000 guesses a second on the travelling salesman problem. I know because I met the guy who built it. I've since just touched that myself, but now down to ~3900 a sec with all the conditions I have to check in a loop.
Their system was written in Java
 
@Kevin okay wow, that was a definite WTF moment haha
 
In fact, I know of other systems written in "compiled" languages that can can be outstripped by good python (well, numpy), so speed often is a poor argument against Python
But there's always OSRM to give you the wtf factor on how fast it can work in C++ :)
 
"good python (numpy)" is C, really
 
7:07 PM
Still in a Python loop
 
depends :P
 
wim
maybe even fortran if you're going down to lapack and blas
 
the fast parts of numpy are c loops of course
 
thats the thing though, its why i dont think python should be called blanket slow. Its the same as calling it an interpreted language. Its not exactly wrong, but its just "off" because its not black and white.
numpy offshores the heavy lifting to C, so its blazing fast. but i cant fault someone for saying numpy is "python turf" so to speak. because it is being used from python and so seamlessly it might as well be taken for granted in the language
or fortran :P i dont really understand how that all works out that much
 
There are a million possible applications of Python that will look nothing like the N-body problem and have completely different relative performance than what is predicted by the N-body benchmark I linked
 
7:11 PM
Numpy must surely be considered part of Python if you had to segment it into a language
 
This is true even if said application never discreetly dips down into C
 
@roganjosh I'm not so sure about that. It's not a strong argument that "<language> is not slow because we have <part of language> that is not slow and also not implemented in <language>"
 
Don't poke the "implemented in <language>" backdrop too hard, that's a leaky abstraction. Everything's implemented in asm eventually.
 
At the same time, "I am coding in <language>. This language allows me to outsource work to <faster language> without having to understand the <faster language>. My code runs pretty fast. but the <language> is slow if i dont use the <faster language> section and write a native replacement."
That turns into a practical issue.
Because, practically speaking, <language> is letting me write fast code.
 
@AndrasDeak if this distinction made any real difference in real life, there wouldn't be swarms of people moving to Python for machine learning
The parent language might not implement the same speeds, but it gives the linkage for other tools that were built specifically for the parent language
It would, I think, be nonsense to consider numpy as anything other than a part of python
 
user521945
7:24 PM
My time is worth doing everything in assembly. That is to say, my time is not worth very much. :(
 
user521945
Also likely to generate confusing errors and web answers like, "Y u no write jvascirpt?"
 
@JackStout mm, I'm pretty sure assembly is important and if you know programming then your time is worth an awful lot
If a problem that's actually interesting pops up on SO, it's possible that that OP's company has spent several days' salary on that person while they're hitting a brick wall but it can be solved in 10 minutes, and the solution can be for a project worth millions
 
Wow, I just witnessed an OP willingly accept an incorrect dupe...
 
OP can accept dupe suggestions? i never knew that
 
wim
7:39 PM
yeah it renders a nice little dialog thing for them
 
@ParitoshSingh Yes, that's why you'll see "Community" in close votes
 
wim
and you can say "thanks, that solved my problem" or "no thanks, i'll edit the post"
it's stupid that it says community user closed as dupe, it should list the OP.
 
aah i see
 
There are way too many partially overlapping questions about all of the various meanings of the * in python... huge mess
and people don't bother finding appropriate duplicates, they just use whichever question they find first...
 
So does anyone know how to iterate over a workbook in openpyxl with another workbook?
 
wim
7:44 PM
will moderators delete stuff like Pow() function gives the wrong output if flagged? or they gonna decline flag?
TL;DR question has false premise/PEBKAC but it got "answered" anyway (answer is a rhetorical question)
 
I really doubt it will be deleted
 
I'd cv-pls and delv-pls before flagging for mod attention
 
wim
I wish people would stop answering questions with no MCVE ... sighs
 
@wim decline for sure
no repro (brain flatulence) stackoverflow.com/questions/55306455/… ^
 
closed
 
7:57 PM
im sorry for bringing up speed in a python chat
 
It's not some taboo subject
 
"hey, do you know how I can speed up this operation?" is a completely valid question
(and to be totally explicit, the answer often is itertools)
 
How long will a 300 Million Item length Search Take?
 
wim
hah, no, itertools is the answer to "how can I make this operation less readable"
 
@wim I just mean in the sense of using generator expressions and iterables as opposed to lists with everything, which python newbies like to do.
 
8:01 PM
hey guys, is tensorflow built on numpy (i.e.: supports ufuncs and advanced indexing/slicing)
 
@RobertFarmer depends on the position of Jupiter when you start it off
 
also idk I find most itertools things I use quite readable. everything can be abused of course..
@roganjosh :crying laughing emoji:
@RobertFarmer measure how long it will take to run the search over a small subset, and extrapolate. E.g. "ok it takes 1 second to search 100k, so can estimate ~3k seconds for 300M"
 
8:28 PM
Alright, So one workbook has job codes stored as 00xx or 000x using zeroes to act as fillers because they must be four digits in that workbook the other just has the plain digits. for example Code 0002 in workbook 1 would be the same as 2 in workbook 2. Is there A way I can compare these entries? They're both strings stored in the workbook rows.
 
In Pandas it would just be a case of converting to ints and back to strings
 
could I just preface wb1_row[0] as int(wb1_row[0].value)
so 0002 and 2 would essentially just be 2?
 
yes, it would just be 2 but it would be of integer type
So be sure that what you're comparing to is also an int and not a string
 
Thats fine, I dont need them converted I just need them to be compared so I can perform the required work on workbook1
 
That wasn't what I was saying 2 != '2'. I suspect the file will be read in as strings and by doing the conversion, your equality checks won't work
 
8:33 PM
Oh I meant place them both as ints(wb1row.value) == int(wb2row.value)
Would that make them compatible or still would there be an issue.
 
Yes, that would be fine
 
So, now is there a way I can delete the row I'm on if it matches the conditions I'm creating for it?
 
You could break the nested loop
But deleting from the file may not be such a good idea
 
How come?
 
Because that data will be lost. Forever. If you fancy your chances at getting this right first time (and keep in mind I've done quite a bit of debugging with you today) then delete it.
Make sure you take backups of the files
 
8:41 PM
Oh, I do have backups Its just the final copy will have the completed jobs deleted from the Workbook and Jobs that are No longer in service also deleted and jobs still incomplete or not mentioned will be kept.
 
i just finished reading about 2 months worth of blog posts from thedailywtf.com
I am a bit in shock.
I blame Kevin for linking to it.
 
rogan so how do i go about deleting these Entries Im on.
is it just wb1_row.Delete()?
 
That's specific to openpyxl and a deleted cell will still exist in the spreadsheet
 
cbg
 
so that would just empty to data and it'd be blank?
 
8:49 PM
So you're probably better just making a new spreadsheet and leaving the originals be
cbg heather
 
i have an interesting little problem.
i'm writing some code that involves the user putting in entries that are then formed into a numpy matrix, that's used for mathematical operations elsewhere in the code.
i want the user to be able to input square roots, constants like pi and e, imaginary numbers, and then standard operations like *,/,+,-.
eval() is frowned upon for obvious reasons, but i've been looking into alternatives and ast doesn't seem to do what i want either - though perhaps i'm looking in the wrong place.
what are my options?
 
i was under the impression that sympy.sympify also uses eval().
 
and, can you trust your "user"?
 
8:55 PM
well...probably?
the program is something other people would download onto their own computers, probably for research use.
 
So safety is a real concern here; your endpoint is exposed to Joe Public?
 
oh. yikes
okay, no eval.
 
yeah.
 
i think you may want to use some kind of mathematical parser then
 
But a hack of eval would just trash their own system?
 
8:56 PM
i dont know much about this area, but i know for sure tools like wolfram alpha do it (and so much more)
 
@roganjosh right...but what if someone else was using their laptop? i don't know, but it just seems like poor form.
 
yea, i dont think opening up a user's system to an exploit like that would be appreciated
 
@ParitoshSingh right. this program doesn't just create numpy matrices, it uses them for a simulation.
 
Uh, does anyone know of a dupe for "how do I make my class support ==" questions? (i.e. implement __eq__)
 
@ParitoshSingh is there something someone else has built out there, is the question, then.
 
8:59 PM
Not that I'm aware of tbh
 
aye. you may have to search through some stuff online, and evaluate whether they arent all using eval under the hood anyways :P
I think Andras might know of something if python has something built along those lines.
 
i wonder if there's some simple dictionary type thing i could put together, that would handle a list of functions, but would result in an error for anything else...
 
Depending on how people interact with the software you might be able to implement logical checks
In fact, all of the responsibility for this probably comes crashing down on you
 
it's a command line interface that's pretty simple - it'll ask, 'what do you want in (1, 2) spot of the matrix: ' and take in the input and store it properly, and then that matrix is assigned to a user inputted key in a dictionary.
 
@heather Seems you have moved on to something other than quantum computing
 
9:02 PM
@Code-Apprentice nope, this is the same program, lol
i'm getting there, though.
 
eval is the easy route, the other options are probably your own evaluations of user input
 
@heather Maybe write your own parser...something like this.
 
it might be good enough to start with, and add onto
 
@ParitoshSingh hmm...i didn't see that one. i was looking at pyparsing. thanks!
 
9:04 PM
@heather so you have outputs to CLI and get an answer back from the user. That's totally possible to cross-reference
 
yep. pyparsing would probably be more robust, but its much more "lower" level.
so you'd have to build a lot more before you get it up and running. (IIUC. found pyparser too while searching)
 
If someone sits at the computer and wants to hack your vulnerabilities with eval, why wouldn't they just delete the files via literally any other method or fire up the Python interpreter and do it?
 
@roganjosh that's fair. so maybe eval() isn't such a bad option after all?
 
@roganjosh You don't necessarily have to be sitting at the machine which is running the code. Say for example, someone writes a Django webapp that uses eval()
 
i think its just a concern of a reputation hit, so to speak, you shipping a product with an exploit like that. alternatively, add a warning like the docs do
saying "dont run unsanitized input" etc
 
9:06 PM
stackoverflow.com/q/39610336/4909087 syntax/indentation error, no repro
 
@Code-Apprentice django is entirely different, but that's not what we're working with
They're building an application that works locally
 
thank you all very much!
 
^^ If you go with the warning route, make sure its clearly emphasized. And i think that should probably be okay
 
i'll probably use eval() for now with a warning, but might use one of the parsers with modifications in the future.
@ParitoshSingh all caps and bold in the readme file =P
anyway.
rbrb, and thanks again
 
9:10 PM
You probably shouldn't blindly use eval because people make mistakes
but security here is less of a concern
 
Do we seriously not have an appropriate dupe target for this question about equality? Do I have to write a canonical about __eq__?
 
That one already includes the answer in the question. I think it's asking how to best implement __eq__, not how to make a class comparable
 
wim
any answer that doesn't also mention __hash__ should not be used.
 
wim
9:15 PM
 
its a really tiny answer though.. i dont know if its satisfactory or not
 
So i know datetime.datetime.now() puts out the current Y/M/D - H/M/S is there a way I can remove the H/M/S
 
wim
not to toot my own horn ...
 
@ParitoshSingh Nice find. I'll polish that.
 
@RobertFarmer yes, by using date.today() instead of datetime.now()
 
9:16 PM
what the import for that date?
nvm
 
... the same as you have.
 
wim
@Aran-Fey __cmp__? please no.
 
I'll write my own answer
 
I forgot to put the initial datetime in the datetime.date.today()
I goofed
 
What the hell is __cmp__. Time for research.
 
wim
9:19 PM
you know what, I'm just gonna hammer this. It's about as exact as an exact duplicate can be.
 
Ok, gone in Python 3. Makes things easier :)
 
@roganjosh yah, I was probably generalizing the discussion about eval() too much.
 
@Code-Apprentice better to have false positives for bad advice than have someone use a flawed approach that leaves them open to attack :)
 
well...back to writing this godawful test.
 
9:26 PM
Best help I can give is print('100%') to that. Hopefully that would buoy you.
 
me: why am I not getting back any values between these two dates?
1 hour later...oh because its 2019, not 2018...
 
To be fair, it did sneak up on us
 
doesn't it always? its 2018 one day, and the next day, and the next day
for 365 days!
then one day its just like "nope now its 2019." sneaky years...and sometimes, it takes 366 days!
 
yes, but this year it decided to put a sheet over its head
 
yea whats up with that?! i can hardly keep up! :p
 
9:40 PM
Legit I think my code craps out if there is a leap year. Just one of the wonderful things on my to-do to fix
 
time-series data that is on the order of days just sucks to deal with.
"how many of these events occur per day?" -- "well the events are variable length so...when is the cutoff for each day? If something starts at 23:50 and ends at 00:10, which day does it belong in? What if there's more time in the one before and after?"
"oh you gotta normalize it now by the number of days in each month"
"oh this day was an hour shorter because DST"
Why can't all timeseries data just be on the order of seconds? lol
 
If we could just normalise our time scale it would be much easier
 
Yea that's why I try to use epoch whenever I can.
 
Mine is not so much about historic data but projecting into the future. For now I can plan for the next 50 weeks from last Monday. But I really think the code will crash on a leap year
tbf it's a minor niggle to deal with, where there is week 53. I just need to get round to it
Not just a leap year. Just week numbers in general.
 
@roganjosh what do you do for work btw? I understand it's data sciency related, but what industry/field?
 
9:50 PM
Primarily I was in vehicle routing. Now it's machine scheduling
Combinatorial problems
 
Machine scheduling for industrial processes/manufacturing?
 
Yes. For simplicity: 8 machines can make 12 products but what should they be making at any one time to meet the sales?
 
@wim did you get a chance to read my comment on the now-deleted brain fart?
 
The reality is about 50 machines and monitoring their output at any one time
 
That's cool. Sounds like a lot of fun small problems to tackle all the time.
 
9:55 PM
It's pretty horrendous to implement tbh. What I've built here is well beyond anything I built before
The flip side is that it's shakey as yam because I'm having to do full-stack development
 
Are you one of the only people working on it?
 
Yes
 
a.k.a. "the computer guy" :D
 
wim
@AndrasDeak yes
 
9:57 PM
OK
 
wim
IIRC it's not accurate
 
how so?
 
wim
only applies if has answers scored >= 0
 
@AndrasDeak pretty much. Headphones in and let the IT department do the "turn of/ turn on"
 
@wim hmm, I don't think I ever heard concrete conditions, only vague hints
let me look up the meta post I usually look at
> The one exception involves deleting a question right after someone posts an answer to it. This (fairly rare!) pattern is seen as so overtly hostile that it does impose a pretty stiff penalty... But that's also a far cry from "self-censoring".
that's what I had in mind, I don't know how "right after" is implemented
 

« first day (3079 days earlier)      last day (1870 days later) »