« first day (3198 days earlier)      last day (1765 days later) » 

8:00 PM
@ParitoshSingh But d doesn't have a first value. its length is zero.
 
@ParitoshSingh that's not a dict value
 
o.o oh. what the heck is this?
 
d['k']: "foo" is some kind of type annotation thing, right? I didn't even know it was syntactically valid outside of a function signature.
 
type annotation
 
I am wondering how d['k']: "foo" which is type annotation is possible like this
 
8:01 PM
@wim What the Actual Yam!
had to nerd snipe me
 
@AndrasDeak Depends, check this for example :stackoverflow.com/questions/57113462/nested-list-manipulation/… it is the responsibility of the OP to specify which solution is required
nowhere is it written thats a dataframe. Why should we assume it(it is as good as guessing a less MCVE question)
I mean that way :)
 
I'm trying to find this wacky annotation syntax in docs.python.org/3/reference/index.html but no luck so far
 
@anky_91 I'm just talking about untagging pandas
 
There's docs.python.org/3/reference/… but that's annotated assignment statements and d['k'] doesn't look like an assignment statement to me
 
disclaimer: dont really know type annotations. But is python itself even aware of a type hint? my first search seems to indicate python itself doesn't really have any knowledge of what's hinted.
 
wim
8:04 PM
well it parses it
 
Ah, the assignment is optional. So it is an augmented assignment statement.
 
wim
perhaps it just drops the data on the floor, I don't know.
 
I want to say "that's dumb" but I'm sure you'll all jump on me with a dozen valid use cases, so I'll skip that part
 
@wim this and the first comment on the question seems to actually indicate that.
 
I know, don't you think pandas should have been untagged here(reading the question alone?)
 
8:05 PM
I konw this:
def h(a: str) -> int:
    return 1

h.__annotations__

# {'a': str, 'return': int}
 
"If the right hand side is not present for an expression target, then the interpreter evaluates the target except for the last __setitem__() or __setattr__() call.". So... d['k'] : int evaluates d but not d['k']
 
but I can't access the annotations of a dictionary key that hasn't even been assigned yet... still looking
 
>>> d['foo']['bar'] : int
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'foo'
 
I did find an question on SO which is addressing this same behaviour, but I guess I am not permitted to share it here since it might hint towards the puzzle
 
rbrb.. :)
 
8:10 PM
When the riddlemaster says "I don't actually know answer, or if it is even possible", I think it's ok to post hints out in the open. We're all working on it together :-)
 
@Kevin except "riddlemaster" needs to be said with a lisp "widdlemaster"
 
okay, here is the question spoiler
 
@Kevin - I updated the code to produce example data frame in the comments
 
@wim it is not possible without inspecting the source. only symbol annotations are stored. annotations for subscriptions, slices and attribute references are eliminated from the bytecode already.
 
@g3lo Thanks, I'm looking at it now.
 
8:13 PM
though they do get loaded...
 
wim
but why are annotations for expressions even allowed?
 
so that type-checkers can do their vodoo
they don't actually run the code
 
wim
why is that needed for expressions?
 
Not just any expression can be annotated, mind you. It's got to be something that could be on the left hand side of an assignment statement
Why you're allowed to annotate the left half an assignment statement, I don't know.
 
wim
it seems harmful for beginners
no error in the REPL makes it seem as though you're actually doing something valid/useful
 
8:17 PM
@wim type checkers are really shitty at deducing the type of complicated lookups
 
@MisterMiyagi Can I walk away from this discussion knowing this is True? Meaning, are you sure. If you are sure, I'm disappointed (not sure why but I am).
 
of course it's not entirely true
>>> dis.dis("""d['k']: foo""")
  1           0 SETUP_ANNOTATIONS
              2 LOAD_NAME                0 (d)
              4 POP_TOP
              6 LOAD_CONST               0 ('k')
              8 POP_TOP
             10 LOAD_NAME                1 (foo)
             12 POP_TOP
             14 LOAD_CONST               1 (None)
             16 RETURN_VALUE
if its in a function, you can inspect the code object to rebuild this
at global scope and the REPL, I think it is impossible though
hm, disassembling a function only shows building the target but the annotation itself is gone
 
Suppose I have a dictionary that contains key/value pairs that I use often. I want a function that returns a copy of that dictionary but updated with overrides to keys and possible other keys.
def h(d):
    c = {'a': 1, 'b': 'c'}
    return {**c, **d}

h({0: True, 'b': 2})

# {'a': 1, 'b': 2, 0: True}
is there a better way to implement this?
 
8:34 PM
I think since you unpack the dictionary you pass before, the duplicate key gets overwritten with the value in d, so it gets the job done, but it's not really readable
How about this
 In [7]: def h(d):
   ...:     c = {'a': 1, 'b': 'c'}
   ...:     c.update(d)
   ...:     return c
   ...:
   ...:
   ...: print(h({0: True, 'b': 2}))
   ...:
{'a': 1, 'b': 2, 0: True}
@PM2Ring hah, what I was thinking too
 
doesn't that change c?... oh but I create a new one every time I call the function! Ok, that seems to work
see! that's why I like you guys.
 
yes, c is local to h() It doesn't exist outside it
 
Sorry. I wasn't thinking straight. :(
 
@PM2Ring it's your non-linear thinking that is most beneficial anyway.
 
@piRSquared if it exists inside, work on a copy of the dictionary in the function
c = {'a': 1, 'b': 'c'}

def h(d):

    copy_c = c.copy()
    copy_c.update(d)
    return copy_c


print(h({0: True, 'b': 2}))
print(c)
# {'a': 1, 'b': 2, 0: True}
# {'a': 1, 'b': 'c'}
@PM2Ring ohh, was there something wrong in that approach?
 
8:39 PM
@DeveshKumarSingh .update returns None
 
ohh but I am returning c, and not c.update()
 
@DeveshKumarSingh yeah, you're good
 
:) My sleeping pattern is even weirder than normal, ATM. So I might make a few mistakes, but I usually notice them pretty quickly.
 
@Kevin - thanks again for your help! When you get a chance to figure out the order, that would be perfect!
 
@AndrasDeak aah you pointed that out in PM's code
 
8:41 PM
@DeveshKumarSingh Your version is fine. Mine was dumb, for the reason Andras mentioned.
 
@PM2Ring aah, early morning in down-under
 
def h(d):
    return ((x:=c.copy()).update(d), x)[1]
 
^ /gasp
 
@PM2Ring today I took a flashlight to walk the dog. At 3 PM.
 
I like to test code before I post, even really simple obvious stuff, to avoid blunders like that, but it's a PITA to do that on the phone.
 
8:44 PM
I can't seem to run a google colab on my phone. I haven't tried a azure notebook yet. anyone have a nice cloud repl to use on phone
 
@AndrasDeak verified in 3.8, works like a charm, impossible to read though
 
@AndrasDeak :D OTOH, I guess Antti might do that. If it were the middle of winter.
 
When I was in seattle, it got dark by 4pm
 
but how were you out in all that rain?
 
it actually doesn't rain as much as in other places
the rain is more of a drizzle
and it isn't the rain that is a bummer
 
8:46 PM
when I went there, it was more of a downpour with winds
 
it's the constant gray... 9 months of no sun (or very little)
 
yes, but when the sun comes out, it's a different city altogether, especially the views over Union Lake
 
I'm a native SoCal person. I missed the sun. I'm back now and I'm happy
@DeveshKumarSingh that is true but I get that year round in SoCal
 
@DeveshKumarSingh Yes. And I've had about 3 or 4 hours of sleep in the last 36 hours. I'm trying to shift my sleep cycle, but it's not working too well...
 
LA or SD?
@PM2Ring that sleep pattern is generally present when you have a assignment deadline in college or project deadline in your job
 
8:48 PM
I drive 66 miles, one-way, from Orange County to San Diego every day.
 
okay so you work in SD and live in Orange County, wow that's a long journey with all that traffic
 
Yes. Hopefully I'll move to SD soon. My wife just has to find a house she's willing to commit to buying. However, I was flying back and forth from Orange County to Seattle every other week for a year when I still worked up there and lived down here.
 
ohh, that's a lot. I hope you flew united or american and not frontier or southwest :)
 
Alaska
 
that's good too
 
8:53 PM
united is the one that when the plane is overweight they might remove some of your teeth to make room, right?
6
 
Yes, that one :D and i had a united flight a week after this
 
@piRSquared That place name always reminds me of Zappa's Orange County Lumber Truck
 
Never heard of that before
 
It's a pretty straightforward rock track, unlike most Zappa material.
 
wim
@piRSquared use a collections.ChainMap instead
this way you put the overrides in a map in front, that can shadow the other keys without destroying that information
 
9:00 PM
Oh yeah! That is a good call. thanks
 
wim
this way you can also allow the map "behind" to change dynamically, and the chainmap can proxy those mutations too
 
That album has an amazing violin piece on it, a version of Little Richard's Directly From My Heart To You
 
Hello all, I just want to understand why decorators are used. I was going through Pytest documentation and they use @pytest.fixture a lot. If anyone could explain in simple terms, its would be really helpful. TIA!
 
just thought of something, at a company that allows work from home once a week, how do they deal with the event that everyone works from home simultaneously on the same day (leaving the office empty)
 
@chan well, do you understand how decorators work? What they do?
 
9:05 PM
No, I have never used decorators.
 
I suggest reading some tutorial about how they work, which might make it obvious why they are used when being used :)
 
@erotavlas I think that in the event that ever happened... no one would be there to notice.
 
even if you'll still have the question it'll be easier for people here to answer your original question
 
:) that's true
 
Yes, I did read some tutorials on geeksforgeeks
Sure, I will do some reading and get back if there's any doubt
 
9:06 PM
good luck :)
 
Thanks @AndrasDeak
 
@chan it's probably not the best material for starters but anyway here's the PEP which made decorators a thing in python. As all PEPs it has a rationale and explanations and examples.
but as always, a (good) tutorial is structured such that it's easy for someone new to the concepts to understand it, which is not necessarily (usually) true of PEPs
(plus the PEP is pretty ancient)
 
 
2 hours later…
10:55 PM
@Tim The term for no-assigned-desks is "hotdesking". (analogous to "hot bunking"/"hot racking" in the navy, where two shifts share the same bunks). Please let's not let people further abuse the coverall term "Agile..."
 

« first day (3198 days earlier)      last day (1765 days later) »