« first day (3366 days earlier)      last day (1581 days later) » 
02:00 - 20:0020:00 - 00:00

2:07 AM
pandas 0.26 is supposed to be the next pandas 1.0, but that's a major leap, "soon" can be as soon as 6-8 weeks and we'd be none the wiser.
Bug tracker says the expected release is 2/1, and they're 96% of the way there, so fingers crossed :)
 
 
2 hours later…
4:19 AM
@cs95 thanks for that :) nice to know
 
 
2 hours later…
user10984358
5:52 AM
is itertools.filterfalse the only way to achieve a not in without the use of a lambda in the following snippet
 
user10984358
>>> not_allowed
{8, 2, 4, 6}
>>> test_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(filterfalse(not_allowed.__contains__,test_set))
[0, 1, 3, 5, 7, 9]
>>> list(filter(lambda x:x not in not_allowed,test_set))
[0, 1, 3, 5, 7, 9]
 
wim
7:13 AM
@TheNamesAlc No, use a list comprehension
 
Good morning guys, hope you slept well? I have a model that has choices and fields like street, city, postal code and country. Do I have to create a string representation for each of the fields in the django model? Thanks
 
 
5 hours later…
12:15 PM
@roganjosh Which conda version is problematic and which version is good? I'm on 4.8.0 and it seemed to have fixed all the annoying solver-related grief from 2017/2018. One tip I learned is it's a bad idea to put both and R and a Python install into the base environment; makes the stupid solver spend more effort (possibly quadratically or something). There will generally be a couple of shared R and Python pkg dependencies, just duplicate them into separate environments, ugly but gets the job done.
@TheNamesAlc [x for x in test_list if x not in not_allowed] like wim said. Btw your code is mixing test_list,test_set, you probably know that.
 
@smci 4.7.12. I think the issue in the end is that the current Anaconda version from here has dependency issues in what it's shipping. Downgrading conda works to fix the first issue, but then it keeps finding conflicts when you e.g. try to upgrade to Spyder 4. There are no irreconcilable conflicts but I think it can't find its way through dependencies. The solution was simply conda update --all
Which puts me on conda 4.8.0 too
 
Semantic question: would you say that a numpy array array([[1, 2]]) with shape (1, 2) is an array with one element (that element being an array with 2 elements), or an array with two elements?
 
12:33 PM
I saw that answer earlier and thought that the former description was unclear in terms of arrays but makes sense with lists. Then again, I don't think you could reliably reconstruct [[1, 2]] simply from "an array with two elements". Do either make sense for arrays?
 
As arr.size the latter makes sense but it's insufficient. And yes, for lists it would be very different.
That was kind of my point
 
@roganjosh 4.8.0 seems to work fine for me. FYI I don't use spyder. If you have issues see the conda questions on superuser, and drop a link here
...much better than the ongoing nightmare that was conda 4.5/4.6 . I think you'll be fine.
Start the New Year with... Desk slavery in an insane company
 
stackoverflow.com/questions/59578478/… (see the nominated duplicate in a comment)
 
Done
 
I have more for you (-:
thanks!
 
12:46 PM
@smci that's dystopian! I have a tough time believing it tbh
closed
 
@smci ಠ_ಠ
 
Oh, I saw the first one yesterday. It reminded me of a Judge Judy case recently (god I love her :P )
 
I only see Judge Judy's work on imgur. Gems like "beauty fades, stupid is forever"
 
Someone emailed a concrete firm to get a quote on repaving a drive. They quoted $6k and this emailer said that was fine. In order to prove they were legit, he needed to send them $300, which he'd immediately send back along with payment. They sent the money and lost contact with him but started the job anyway. The actual owner of the house came back and they'd obliterated her driveway while she was at work with a jackhammer
 
12:59 PM
firm's fault
 
Oh yeah, totally. But could you imagine coming home to find a load of workmen just attacking your driveway?
 
no, I live in a condo ;)
 
Ahh, that's good planning for defense against this kind of stupidity :P
 
I totally can, run of the mill construction business ethics where I live (you tell them "fix the pavement, don't touch the driveway" and they hear "fix the ... driveway")
also "call me before you start" somehow gets picked up as "absolutely do not call"
 
I watched a stand-up yesterday on tv, guy said he had to call a locksmith to break into his own flat. After 5 minutes and -4 locks he joked "Oops, this is the second floor, I live on the third". But this is Hungary :D
 
1:03 PM
The best part, after them wiring $300 to some unknown and losing it, is that they wouldn't pay up because she spent $4k getting it fixed herself, and they said that quote was outrageous... despite having initially quoted $6k for the same job themselves.
 
@AndrasDeak ...sounds similar to Amber Guyger's defense for shooting her neighbor inside his own apt, claiming implausibly that she believed she was in her own apt and trying to invoke Texas self-defense standards. She was convicted of murder.
 
Ugh
 
Every week or so I see a question on the HNQ bar like "this person wants me to send them money, which they promise to send right back. Is this a scam?" and the answer is always "yes" with a hundred upvotes
 
But they wouldn't let them lie, not on the internet
 
But there's always that one salient fact, like they sent a picture to prove they are real
 
1:18 PM
Watch out for the inverse, "This person sent me a ${X+200} check for a ${X} service I offer, and asked me to send them a $200 check back. Is this a scam?", which, you guessed it, is a scam
You write your check, they cash it, the ${X+200} check bounces, they disappear
 
The mere concept of cheques baffles me to be honest
 
Even if your bank account displays that it has X+200 more dollars in it than before, the bank can say "oops, just kidding" and revoke it later
 
1:37 PM
Is this question a "variable number of variables" dupe, despite the title?
 
Clickbaity headline is not as meta as it sounds: This veteran started a code bootcamp for people who went to bootcamp
 
2:08 PM
Problem: I have a directed graph where each node is either 1) empty; 2) occupied by one unique object. Objects can move between nodes if the nodes are connected by an edge, and if the destination node is empty when the object arrives. I want to move each object up to once, simultaneously, and maximize the number of objects moved. Is there an efficient algorithm to choose whether/how each object moves?
Here are some test cases.
I spent a long time trying to devise a strategy based on coloring each node based on whether it's empty and how many nodes point to it and how many nodes it points to and the colors of all its neighbors, but I'm pretty sure I can't solve this with a finite number of colors
In test case #6, node E knows that both C and F want to move into it, and it knows that it can move into either A or I. Just by looking at its immediate neighbors, it can't decide which one to prefer
And every other node just knows that it has one parent and one child node, so it's not as if I can first color the longer loop with a higher-priority color or something
 
oof. so you want to pre determine which set of nodes has the greater number of moves, and cycle them and if it's a tie between sub groups you want to "randomly" pick one since you wouldn't care? And I'm assuming you want this done if possible at NxM spped ?
 
2:24 PM
Pretty much.
 
I'm assuming you don't know how many nodes there are and your problem can scale infinitely or so to speak ?
 
Let's say, in case of a tie, I want to move the lexicographically smallest object. So in test case 1 I would move A instead of B because "A" < "B"
 
str()'s signature says it has utf-8 as its default encoding but I get different outputs from str(resp.read()) and `str(resp.read(),'utf-8'), would someone explain it?
 
I know how many nodes there are. I probably won't have more than 10,000.
 
Are the words flipped? Seems like 0 is what I expected, and 1 is what I actually got
 
2:27 PM
@aderchox what is resp ?
 
@Vader Please don't post text output as an image, especially in unreadable color-on-color schemes.
 
How is this unreadable? Also It's not one text window, but rather from an IDE. It's not like it's against this rooms rules. I posted 1 small image
 
@aderchox Just to be sure, I recommend trying import sys; print(sys.getdefaultencoding) to verify that str's default encoding really is utf-8.
 
@MooingRawr it's response from urllib.request.urlopen
 
@Kevin similar suggestion of what you've tried. have you tried to find sub groups of nodes that are circular in the graph, and then finding the largest one to move, and what came of it
 
2:29 PM
@Kevin I did, it's utf-8.
 
I thought that might be the case, but it's good to have a sanity check :-)
 
@Kevin yes thank, I did locale.getpreferredencoding() too.
 
interesting... not sure why it would be different. could you provide the b string that resp is equal too or can you create a mini reproducible example so we can run it on our machines?
 
@MooingRawr I toyed with that, although it's not always correct to move each element of the longest cycle. Consider the example:
A -> B
^    |
|    V
C <- . <-- D <-- E <-- F <-- G <-- H <-- I
If you move each element of the ABC cycle, you move three elements. If you instead move the D-through-I noncycle, you move six elements.
 
okie, reading your original issue doesn't state that you don't want the graph to be locked up. I should have guessed that...
im assuming that's the case on why you don't wanna move D->I
 
2:33 PM
To be clear, I do want to move D through I. That is the desired behavior.
 
I thought the point was just to maximise the number of moves
 
oh....
so yeah couldn't . <-- D .... <--I be a sub group and A->B->.->C ->A be another sub group ?
 
But how do you determine the group's boundaries?
 
im getting confused on why it's not correct to move the longest cycle.
 
Because 3 is smaller than 6
 
2:34 PM
if you get back to where you start but I guess that's not MxN anymore
huh yes because 3 is smaller than 6,you would want to move 6.. no? since you want to move the largest cycle, Either I'm having a major brain fart or I'm missing something either way. I'ma go get some tea.
 
Jumping back to aderchox's problem, here's an example object where str(x) behaves differently than str(x, "utf-8")
>>> str(x)
"b'foo'"
>>> str(x, "utf-8")
'foo'
 
@MooingRawr see here the line 18: pastebin.com/ta1hkiWc
 
This behavior seems well-defined by the docstring: "If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object)."
 
@Kevin This is quite an interesting problem. I'm curious if there is an area of application for you or whether this is just curiosity?
 
@Kevin Yes saw that but don't know what "expose a data buffer" means.
@Kevin hmm... Can you explain it a bit?
 
2:41 PM
@aderchox Me neither. Let's see... docs.python.org/3/library/stdtypes.html#str goes into more detail. Essentially, the object must be a bytes object, or an object that stores its data in an "underlying bytes object".
I'm 80% sure that resp.read() returns a bytes object, so you're good there
 
@Kevin yes its a bytes object
 
(oops, I left out the line >>> x = b"foo" in my example code. Oh well)
 
@Vader Ok I zoomed that image up about 6X and now I can read it. It looks like the args to assertEqual are in (expected, observed) order, the reverse of what you have given. Unfortunately, the args are just called first and second, so no help on which is which. Try putting the 0 as the first arg instead of the second.
 
Anyway. Long story short, when converting from bytes to str, you probably don't want to use one-argument str(). Personally, I like to call the bytes object's .decode() method so there's no ambiguity
@roganjosh I was trying to write a cellular automaton whose rules ensured a "conservation of mass" where the number of live cells always stays the same. I got something that kind of worked, but objects can only move into cells that are currently empty, and there's a bit of a combinatorial explosion because local behavior is dependent on every node within 1 unit of both the start and end node
 
@PaulMcG ahh, now I understand. thank you
 
2:54 PM
And that's only in a single move. I would imagine that a greedy approach on a single generation can greatly hamper subsequent generations if the objective is to maximise the number of moved objects each generation
 
Yeah. In the example above, moving six elements on the first generation means that nothing moves ever again. Alternatively, moving the three element cycle lets you move three elements every generation forever
But I'm not concerned about optimizing number of movements over multiple generations
 
@PaulMcG Also, The image I uploaded was in a read-able size, albeit on the small side. I think SO just shows a small thumbnail. You don't have to zoom in on the chat, just click the image and it will pull it up at it's original zoom
 
@Kevin so why is 6 not the correct movement over 3 then in that example before ? if we only want to care about one iteration of movement, why not just find the largest sub cycle.
 
I think you're stuck with heuristics either way. I guess the starting point is alpha-beta pruning but, with 10K nodes, I think "bit of a combinatorial explosion" might be an understatement :)
@MooingRawr it is the correct move
 
3:09 PM
6 is the correct movement in the problem that I have posited. 3 is the correct movement in the hypothetical subproblem about multiple generations that roganjosh posited.
 
i see...
but yeah I doubt you would get something as fast as N M, cause you would have to determine the largest sub group rotate tha-.... oh wait..... what happens if multiple generation is finite, are we going for finding "the most generation of moves you can make before locking up / find the infinite"..
 
@AndrasDeak noted. I think that should also be added to the rules though.
Also which of these is more pythonic? x in [0, 1] or x == 0 or x == 1 ?
 
Every rule we add means another 10% of users will think "this is too long, I'm not reading them" so at some point we've got to hope that people just try their best
Guideline: keep accessibility in mind when posing problems, and remember that text is almost always the most accessible format
 
3:24 PM
Will do. thanks kevin
 
@Vader I often use both, so I don't think it's a big deal either way. There's also x in (0,1) and x in {0,1}. I have never bothered to test which of these is fastest.
All of the in approaches have considerably fewer bytecode instructions than the equality test, but who knows if that translates to better clock time
 
I will test it
 
The big O complexity of membership testing for sets is superior to membership testing for tuples or lists, but there might be some overhead because it has to hash the argument
Hashing is pretty fast for small integers though
 
I think very short tuples are usually faster to create than very short lists...I remember this coming up annually, but I can never remember the answer. It might be "don't worry about it".
 
$ python -m timeit -s "x = 1" "x in [0,1,2,3,4]"
10000000 loops, best of 3: 0.0274 usec per loop
$ python -m timeit -s "x = 1" "x in (0,1,2,3,4)"
10000000 loops, best of 3: 0.0273 usec per loop
$ python -m timeit -s "x = 1" "x in {0,1,2,3,4}"
10000000 loops, best of 3: 0.108 usec per loop
$ python -m timeit -s "x = 1" "x == 0 or x == 1 or x == 2 or x == 3 or x == 4"
10000000 loops, best of 3: 0.0297 usec per loop
@AndrasDeak you were right :p
 
3:32 PM
It's unclear to me whether Python is smart enough to only create [0,1] once, even if it's inside a loop or function or whatever. I think "yes" but I haven't tested it thoroughly
 
so anything but a set
 
Kevin, what happens if you have the following graph:
 
$ python -m timeit -s "x = 1; y = {0,1,2,3,4}" "x in y"
10000000 loops, best of 3: 0.0241 usec per loop
$ python -m timeit -s "x = 1; y = (0,1,2,3,4)" "x in y"
10000000 loops, best of 3: 0.0278 usec per loop
seems like the set had to be created every time, list and tuple got reused
 
I notice that dis.dis("x in {0,1}") shows that {0,1} is a frozenset, so the compiler is at least smart enough to notice that it never gets mutated
 
@Arne During one of those comparisons light travels 8 meters...
 
3:36 PM
A -> B     . --> Y --> X
^    |     ^           |
|    V     |           v
C <- . <-- D <-- E <-- F
 
I'm worried that timeit doesn't enjoy the potential benefit of "create consts exactly once at the beginning of the program" if it's trying hard to create independent environments for each loop
 
are we saying we are only moving sub cycles only or can D move left and E F X Y shifts as well but for future generation only E F X Y would move ?
 
@AndrasDeak I always wondered, does that mean that information travels 8 meters worth of my cpu?
 
@MooingRawr Hmm, I'll draw up the expected behavior.
 
cuz if D can move left, I give up :D cuz then we have to find the sub cycle but then find all the outer empty slots that can be moved into immediately
 
3:38 PM
I'm inclined to say that D would not move left here, although it might be possible to construct a similar example where D does have a choice
 
Would D not just move up?
 
yea that's the question rogan
 
Lots of loopy fun to be had there :)
 
if D moves up then yes it's just a matter of finding sub group that's the largest that can move, and if we need to worry about future iterations then we just need to check the next move and so on and so fourth else we are done
but if D can move Left I would want more tea :D and yes so much fun random snags . I love graph theory.
 
If D moves up, though, doesn't that create an infinite loop?
 
3:41 PM
Yea which is fine...
his question doesn't state that future generation moves must be finite.
it was part of the question of what happens if we brick the graph and there's no more possible future moves
 
Where was it? The only requirement I saw was that each generation maximises the number of moves. Granted, an infinite loop does a good job of that... except it never actually creates a single generation
 
disgusting, i love it
 
Oops, I was wrong in chat.stackoverflow.com/transcript/message/48241788#48241788 that it's possible to lock up the graph by moving more objects into a cycle. I'm not sure why I thought that. A cycle can continue moving even if it's completely full.
As demonstrated by case 5, which has a full cycle in the initial state
 
I think case 9 addresses my point. I'm not sure how you create some stopping criteria. And mooing's example was a simple illustration of the problem. With 10,000 nodes.... err
 
3:49 PM
An interesting challenge but too new to post here, so consider this embargoed for another 44 hours. Number winning streak ID's in pandas. jezrael's solution is neat, I wonder if there's anything simpler.
 
If by "create some stopping criteria" you mean "identify whether a particular graph will eventually enter a state where nothing moves ever again", it does seem fairly tricky to determine
An acyclic graph definitely terminates eventually. Cyclic graphs come in three flavors: 1) definitely terminates eventually; 2) definitely loops forever; 3) may terminate based on decisions made
Here's an example of each: pastebin.com/ypG8US5x
 
Where is this graph cycle problem from?
 
Agh, I keep making typos in case 10. I hope I fixed it.
 
@Dair it started here:
2 hours ago, by Kevin
Problem: I have a directed graph where each node is either 1) empty; 2) occupied by one unique object. Objects can move between nodes if the nodes are connected by an edge, and if the destination node is empty when the object arrives. I want to move each object up to once, simultaneously, and maximize the number of objects moved. Is there an efficient algorithm to choose whether/how each object moves?
 
See also chat.stackoverflow.com/transcript/message/48241716#48241716 which describes my half-baked motivation
 
3:56 PM
Thanks
Where do cycles come into play with this?
 
Cycles are the reason that I can't find optimal solutions with a single pass over all nodes
 
@Arne not sure what you mean
 
(I think. 65% confidence that an efficient solution exists for acyclic graphs)
 
@Arne if you mean whether it takes 8 meters of wiring for that computation to be done: I don't think so. It's just a way to visualize these very short time scales, because light is fast^[citation needed]. I imagine a lot of the time is not about currents going from A to B but rather capacitors and transistors acquiring charge or being depleted, which doesn't involve any kind of "large"-scale movement.
 
see this went from a simple let's find the easy longest sub cycle and rotate, to lets find the one move that will create a chain reaction and then rotate
 
4:04 PM
Re: cpu time vs the physical path of information: In any case, the "speed of electricity" is somewhat less than c -- somewhere between 0.5c and 0.99c, according to en.wikipedia.org/wiki/Speed_of_electricity
 
if there was no cycle then you would just have a simple push
 
Maybe instead of looking for an efficient solution you should prove the problem is in a bad complexity class :P
 
Advent of Code admin, please contact me, I've got a day 24 problem you can use for next year
 
ahahahahah, please no... i like to finish my AoC on a timly and efficient manner.... but on the plus side we would get a solution for sure I guess
 
"Pfft, this is just a simple application of Steve's Lemma, which can be found in the out-of-print 1974 edition of Graph Problems Obscura, available in the restricted section of the Library of Congress", says user that solves the puzzle at 12:00:45 AM
Still holding out hope that someone will ping me today with a link to the exhaustively documented solution. Here's to you, users that read through the entire transcript every day to see if they missed anything cool
 
4:19 PM
Until that day at the end of the year, I assume you want something that can actually be run? Can you use something like Tarjan's strongly connected components algorithm and find extreme nodes (like I in your example) and assume they terminate at . as a heuristic approach?
 
ugh something tells me we would have to have a state checker that checks each possible moves and run the one that affects the most nodes. we can simpleify this by sub grouping things, but then it creates a headache when your node leaves for another sub node. unless you group 2 sub nodes as one... but then that doesnt help cuz u will end up grouping the whole graph
 
Then you at least have an approach that deals with this example and you have some constraints to work within on each generation
 
I suspect you can "subgroup" things by identifying nodes that have exactly one parent and one child, removing them, and somehow annotating the edges it used to own... No point in evaluating all of ? -> A -> B -> C -> D -> E -> . -> ? when you can simplify it down to "? -> [uninterrupted run of length 5 with one empty slot] -> ?`
 
That was my thinking. I meant to put a comma after the link to the algorithm; I'm proposing two different tests
Assume that a node is either in a cycle or part of a chain of nodes starting at the extreme nodes
 
Hmm, maybe
 
4:26 PM
I'm aware of how this is easily broken, but it gives at least a start
 
wim
4:40 PM
@AndrasDeak This person has your gripe reddit.com/r/adventofcode/comments/eh8s3d/…
 
Hello PyExperts.. Happy New Year to all!!!
 
@ranit.b happy new year from a PyLearner ;)
 
@wim meh
 
If I'm not disturbing your discussion, can I ask a question reg issue I'm facing installing NumPy on Win10 64-bit ?
 
Yeah
 
4:51 PM
my one huge phrasing issue was with "<thing> starts labelled 1, 2, ..." when in fact it started with 0 :/
 
I 'm afraid that I'm hitting a bug!
 
hello
 
Hey @AndrasDeak
 
Just ask your question and we'll see if we can help. I don't use windows but I use numpy.
 
Sure!
For reference, this's my question detailed -- datascience.stackexchange.com/questions/65804/…
This error "ImportError: dynamic module does not define module export function (PyInit__multiarray_umath)"
 
4:55 PM
you should explain in your question how you installed numpy, because that's key information with a potentially broken install
 
What does "Don't have access to SO" mean? Are you blocked from posting questions?
 
It also looks like it may be a known issue.
 
Ah! Good pointer. Let me quickly put that in my question.
 
Did you also read that wall of information that numpy told you?
 
@roganjosh Unfortunately, yes! :( Tried a lot to revive, but no.
 
4:56 PM
eh
guess it'll be closed there soon enough
 
@AndrasDeak Yes, I read and tried different ways of installing NumPy.
Closed what? Sorry, didn't get your point.
 
In any case, I would suggest that you install Anaconda if you want the data science stack in Windows
 
Installation problems are hard, my thoughts and prayers are with the afflicted
 
@wim nevermind, I misread what the post is about. You're right.
 
4:58 PM
@roganjosh - Yes, I was thinking about using Anaconda or Jupyter notebooks.
 
try the former
 
Okay!
 
Jupyter comes with Anaconda if you install from here
 
Yes, so why not install Jupyter which will cover Anaconda as well ?
 
because that's not how things are
 
5:00 PM
I have a very fundamental doubt though -- I use currently PyCharm editor on vanilla Python/PIP library installations. Using Anaconda, can I still be able to use PyCharm?
 
Simile: roganjosh is telling you to install windows because it comes with putty. You're saying you'll install putty because it comes with windows.
 
Apologies if the question is gravely wrong.
 
It's fine
 
Just the jupyter vs anaconda bit.
 
As for Pycharm, I'm not totally sure, but you should be able to point it to the python interpreter that comes with Anaconda. I'm going on 99% certainty that this is possible and simple
If you don't want that (and now I'm a bit confused about why you are suggesting you want to use jupyter when you now want Pycharm), you can install an unofficial binary
 
5:04 PM
here is a note for Pycharm with Anaconda
 
If you do end up installing the binary and don't know what MKL is, I suggest downloading a version that comes with MKL
 
Overwhelmed with help and advice.
I think I will go with this approach -- Install Jupyter and point my PyCharm to use Anaconda's Python interpreter.
Does that sounds good? :)
 
I can only comment on the paths I've used in the past, which was my first link that gives you Jupyter
(In the past being yesterday with a new laptop)
 
Thanks @roganjosh
 
@roganjosh lol :D sounded like few yesrs back ;)
 
5:08 PM
OMG!! Do i see @MartijnPieters in the chat room?
 
@ranit.b you have a few suggestions, try and see what's going through, that'd be a learning too :)
 
@anky_91 It's a well-trodden path for me, but the most recent hike was yesterday :)
 
Sure Anky! Thanks.. Exactly gonna do that.
Food for weekend.
 
@roganjosh okay :)
@ranit.b Nice :)
 
Guys, any suggestion on how to resolve the questions ban? It was just because I was not asking questions appropriately (sadly that's what SO thinks) and not marking the open questions closed. I did all of it later, but still I'm barred from asking questions on SO.
 
5:13 PM
I think I've shut down a lot of things I didn't want to have with Windows 10 (Cortana was booted out immediately) and I've just loaded Ubuntu for Windows. I'm "coping" so far :P
 
I'm out for a while guys. Will resume here in few hours. Gonna work night out today :) Got some ideas to work on... Anybody wants to collaborate ? Lol
I'm just thinking about random projects and challenging myself (but thus crap NumPy issue came as blocker - when i upgraded my OS to 64-bit)
I can tell one-liner about the latest self-challenge. :)
 
@ranit.b yes, but it's rude to randomly ping people for no good reason
 
Oh sorry! But ping whom?
 
Martijn in the message I replied to
rhubarb for a while
 
rbrb Andras
 
5:20 PM
So where's this EOL party going on?
just in chat?
 
Sorry Andras. Didnt realize that. Won't happen again. Apologies.
 
<feels awkward to point out that the counter is now going upwards>
@Code-Apprentice we saved you some cake, though
 
cabbage, grean bean here. I want to know what azure virtual machine are for in development. One was setup for me and I don't understand why I should use it. I have google but I didn't get much from there.
 
@superv would it not be better to ask your supervisor and/or the people who set it up given that they know the context of why they did it?
 
@roganjosh, I did ask but the lead developer just said I needed it and he won't say any further. That is why I am asking here.
 
5:33 PM
@roganjosh lol, I didn't even notice. Wondered if it was delayed from the first of Jan.
 
may be they can only use microsoft VM
 
Virtual machines are nice for configuring your environment without altering the environment of other projects. Cloud computing is nice for being able to access services from multiple computers
 
primes[num**2:n:num]
what does the double : mean?
 
@roganjosh thanks
 
5:39 PM
@Kevin Thanks for the reply. Does it mean I shoud have been doing all my development in the virtual machine instead of my local machine?
 
I think that's a fairly typical practice, yeah. I usually don't bother for really quick little projects though.
 
wim
@AndrasDeak oops, I should have linked to the O.P. not that reply
interestingly a couple of the comments says they had an O(n log(n)) general solution
and one of them still got 21st on the leaderboard, amazing
 
Cool. I guess I have to learn it now. I am working on this django model (link here dpaste.com/0JNF84P) I know I have to add the string representation to the class. My question is, do I have to do it to each of the variables in the class?
 
5:59 PM
Hmm, I'm surprised that Django doesn't appear to have any way to automatically generate a __str__ implementation that simply returns a readout of its class attributes.
My "why isn't this seemingly common useful thing easier to do?" sense is tingling, which 99% of the time means 1) it's not all that common and useful; or 2) there is an easy way, but I missed it
 
wim
You can't dig upwards <-- interesting opinion about the rise of Python in the computing world
 
What's the 1% outcome? :)
 
wim
@Kevin both 1) and 2)
there is model_to_dict (then you can just use the usual str for dicts)
 
@roganjosh If that is for me, the migration work. I just want to know if i must add it to all the class attributes?
 
wim
but it's not all that common or useful, because typically in Django code you're dealing with querysets and not with single model instances
 
6:04 PM
@superv it was to Kevin, having only covered 99% of the time but giving options that seemingly cover every case. They are debating your issue
 
@roganjosh When it's not #1 or #2, then the simple common thing doesn't have an easy solution because nobody has written one yet. The world is waiting for a hero, and that hero might be me.
 
Thanks @roganjosh
 
So if I understand wim's advice, then @superv does not need to laboriously define a __str__ implementation for each of his models that manually adds every class attribute to a string -- he can just use model_to_dict
 
Thanks @Kevin and @wim. I will check that out.
 
Or maybe superv was asking "Do I have to define thirty separate __str__ implementations for the thirty class attributes used across all of my models?", in which case the answer is "no, because there's no point in defining multiple methods with the same name in one class. You need one __str__ per model, not one per attribute"
 
6:09 PM
I think it's more for debugging purposes. Having self.address doesn't make sense in the example, you'd probably want:
class Landlord(models.Model):
    user = models.ForeignKey(UserModel, on_delete=models.PROTECT)
    address = models.CharField(max_length=255)
    social_security_number = models.CharField(max_length=255)
    email_address = models.EmailField()

    def __str__(self):
        return self.user
So you can say "ok, I have an instance of Landlord and the username is {user}"
 
wim
^ I hate classes that do that
 
@wim Makes sense, but how does the queryset decide how the results should be displayed? Doesn't it call __str__ on the model? Or do I misunderstand the advice given at stackoverflow.com/a/56339054/953482?
 
wim
If you're a mutable model, don't pretend you're a simple string.
Makes debugging much worse.
 
Well, with a bit more info than just self.user
 
return f"Landlord({self.user})", perhaps
 
6:12 PM
Does it mean defining one per attribute is sufficient and I can randomly pick a particular attribute?
 
wim
@Kevin the queryset will use repr, as it should
 
@superv Enough to identify what the object is and some instance identifier
 
@superv Perhaps you could pick the attribute(s) that uniquely identify the object. If your table has a primary key, that's a good choice.
 
wim
because if you are actually interested in the fields, you use queryset.values(...) or queryset.values_list(...). you generally don't really care much about the repr of the queryset or the models.
 
from django.utils.encoding import python_2_unicode_compatible

@python_2_unicode_compatible
class Book(models.Model):
    name = models.CharField(max_length=50)
    author = models.CharField(max_length=50)

    def __str__(self):
        return '{} by {}'.format(self.name, self.author)
 
6:15 PM
@wim Ok, so instead of defining __str__ for all my modules, I should define __repr__? Or does Django provide a nice default implementation of __repr__? If so, why does the answer I linked claim that, by default, querysets return nondescriptive results like <QuerySet [<Blog:>,<Blog:>,<Blog:>....]?
 
I was looking at the example above, that was where I thought I have to define eacth attributes but thanks for the explanation.
 
wim
You don't have to define __str__ or __repr__ for your models. Queryset values objects return fields in Python dicts, and queryset values_list objects return fields in Python lists.
 
Perhaps I misunderstand the scope of "typically in Django code you're dealing with querysets", and that doesn't include "printing a queryset with the intention of seeing the field data for each of your rows"
 
wim
It's the same way in Python you will get <A instance at 0xcafeb4be> unless you define some other convenience
 
Thanks so much @wim, @Kevin and @roganjosh. I really appreciate :)
 
wim
6:18 PM
you usually don't need anything better than that. In particular in Django it will be error prone to try and define anything better than that, since converting to a string will be taking data from a db, decoding it... and making queries!
 
@Kevin For SQLAlchemy, I'd just use:
for item in queryset:
    print(item.__dict__)
But that would just be debugging
 
wim
those charfields are maxlen 255, and text fields might be megabytes long. don't risk putting that into your model string representations - <Blog object at 0xdeadbeef> is just fine.
 
I haven't set __repr__ or __str__ on any of my models because.... I've never needed them
 
wim
@roganjosh exactly, you don't need them.
 
I'm not sure I understand "Queryset values objects return fields in Python dicts". Are you saying "queries such as Blog.objects.all() will return a dict of human-readable field strings, and the linked answer is lying that it returns <QuerySet [<Blog:>,<Blog:>,<Blog:>....]", are are you saying "the linked answer is telling the truth, but there is a quick and easy way to get the human-readable dict equivalent, so you don't need to bother defining __repr__", or, I don't know what?
 
wim
6:21 PM
@Kevin Blog.objects.all() returns a queryset. Blog.objects.values() returns an iterable of python dicts (one dict per row in db).
the keys of the dicts are field names, and the values are the fields (data from db)
 
Ok, makes sense.
 
wim
The queryset is lazy
 
@Kevin I have several Django models that have like 20 fields. But a useful str() or repr() is like 4 of them at most.
 
wim
it doesn't fetch rows from db until they need to be presented.
this is good, because it's the templates responsibility to present the data, not the model.
makes sense?
 
Yeah.
Thanks for bearing with me. My default approach to exploring databases is using select * in a sql terminal, so inspection via ORM is outside my wheelhouse.
 
6:24 PM
@Kevin "... it returns <QuerySet [<Blog:>,<Blog:>,<Blog:>....]" Technically, that's the repr() of the thing returned.
 
Yeah, bit of technical imprecision there on my part
 
And I think that when you call repr() on the query set, it in turn calls repr() on each thing in the set.
and I'm jumping into the conversation while reading it and trying to figure out what it's all about
@superv When I write a __str__() method for a model, I just use the fields that uniquely identify the instance. But then I don't commonly use print() for debugging, so I don't need it to print out all of the fields in the model.
 
6:42 PM
@Code-Apprentice Thanks. Is it that it is because I am new to Django or its just sheer laziness, I am thinking why use Queryset when you can just migrate the db and test it in application.
 
wim
@Kevin I skipped past it because it was on pastebin, which I can't access.
 
Kevin let me know when/if you got a solution to your question, I have to finish my work today so I can't play with it ;(
 
Maybe I can implement 3sat in it, in which case we're doomed.
 
stackoverflow.com/questions/59583709/… no MCVE. 2 upvotes in the space of 1 minute. At least the new user got 18 rep for it...
Closed, thanks. The rep changes on questions aren't getting to me, I promise <trembling>
 
6:59 PM
Thanks. I think you've linked this to me in the past. Recently, there's been a couple of decent questions from new users so I'm hesitant to block it completely, but the 2 upvotes on that are suspicious to me at best
 
wim
maybe this script should be added to userscripts page, it's not there currently when I went looking for it.
not perfect solution, but incredibly useful and gets rid of ~90% of crap
 
Added
 
Somehow I only just realized that there are actually people who use the stuff I write. Weird feeling
I guess it's because I still haven't actually properly published any of my python stuff
 
I like to believe I have never written anything useful, ever
(I say, as I pointedly ignore the four extra buttons/indicators that I've added to my own chat interface)
 
7:16 PM
And there's probably half a dozen people who have your spoiler markup script installed :P
 
My projects are like sculptures that I construct out of sheet metal and abandon to the elements deep in the forest. If someone stumbles upon it and appreciates it, that's their problem.
 
And maybe even an entire company running on KevinScript tearing up the marketplace
 
7:49 PM
is there a python function to compute: 𝐷_𝑦(𝑛), the day of the week (with Sunday being 0) that September n falls on in the year y?
 
I'm pretty sure that's in the stdlibs somewhere
Some arithmetic required since it considers Monday to be 0, not Sunday
 
_, _, day = datetime.datetime.now().isocalendar()
So you just need to provide a datetime object and call isocalendar() on it
 
datetime.datetime.today().isoweekday()%7 is a start
 
Whatever happened to "There should be one-- and preferably only one --obvious way to do it" -_-
 
datetime.datetime(2019, 9, 1).isoweekday()%7
thanks all !
thanks @roganjosh
and @Kevin
 
7:55 PM
Why %7? It already starts with Sunday as 0
 
weekday is zero-indexed, isoweekday is one-indexed
No, I don't know why
 
ah!
that definitely confused me :)
is it zero indexed to sunday ?
 
datetime.weekday() - Return the day of the week as an integer, where Monday is 0 and Sunday is 6.
datetime.isoweekday() - Return the day of the week as an integer, where Monday is 1 and Sunday is 7.
 
Yes, you can see that from the example I gave using the current time
 
ok so I need % 7 as I want Sunday to be 0
 
7:59 PM
Who are you replying to here?
 
I was replying to "Return the day of the week as an integer, where Monday is 1 and Sunday is 7."
 
02:00 - 20:0020:00 - 00:00

« first day (3366 days earlier)      last day (1581 days later) »