« first day (4546 days earlier)      last day (402 days later) » 

6:03 AM
hi
or should I say
"hello world"
 
 
1 hour later…
7:25 AM
You should say "cabbage" ;)
 
7:35 AM
But "hi" and "hello world" are also fine. ;)
Welcome!
 
 
3 hours later…
10:31 AM
What is the best practice in python if you have a variables first assignement in local scope and you need to access it in enclosing scope, currently I declare the variable as an empty string in enclosing scope and then just its value gets changed in local scope.


```
foo = ''
with open(myFile, 'r') as file:
<indenthere> foo = file.read()
<end of indent>
#use foo here
```

Hope the question makes sense
 
with doesn't create a new scope
So you don't need to "declare" a variable before it
 
Enclosing scopes are created in far fewer situations than you expect.
In particular, there isn't one here; inside and outside the with block are the same scope, so there is not in fact any "need to access it in enclosing scope".
 
10:51 AM
If there was something that creates a new scope (function definition being a most common example), you "should" use nonlocal/global keyword to mark a variable as coming from outer scope:
def fun1():
    foo = "foo"
    def fun():
        nonlocal foo
        foo = "bar"
    fun()
    print(foo)
fun1()
"should" is in quotation marks because you generaly should avoid using those keywords if possible and reassign variables in their scope explicitly
 
 
7 hours later…
6:17 PM
@Dodge will you be at PyTexas this weekend? Anyone else?
 
 
3 hours later…
9:45 PM
Hello everyone. Not sure if this deserves an actual question but, suppose I am adding a column to a pandas dataframe with values from another column processed by a function. Is there a way to know which row from the dataframe is being executed by the function?

df['new_column'] = df['data'].map(self.process_data)

I want to know this for debugging reasons. I know that from inside the function, I can print the parameter passed, but I was wondering if I could print the index of the row being processed.
 
BTW, you can't mix regular prose and code blocks in the same message. See tinyurl.com/urnzp7k for the code formatting guide in chat.
 
That too
As far as your question goes, I'm not sure you'd get anything meaningful out of doing that. df["col"].map(func) vectorizes func across all members of the targeted column, which may occur out of order. What, exactly, are you trying to do? What are you trying to debug?
 
Thanks for the formatting tips!! I was being generous with "debugging". I really just wanna see how far I am in the execution lol It's a big df so I just wanted to have an idea, really. I didn't know that the execution may occur out of order, so I guess that's not possible after all.
 
Using built-in map would be considerably worse, right? Because in that case you could wrap your series in tqdm.tqdm.
 
10:05 PM
Does built-in map() support parallel execution? I could see for large datasets it being considerably worse. I think the point of using df.map() is that it plays well with Series and DataFrame objects and is designed to divide and conquer using multithreading, if not multiprocessing as well.
 
Googling tqdm pandas shows that tqdm is indeed Pandas-friendly, so maybe you could use it directly.
 
I doubt tqdm(series) would expose the map() method though. This was my first thought.
 
ah, needs opt-in
I actually tried it and it didn't work out of the box
and tqdm(series) doesn't seem to expose map(); based on that snippet it looks like tqdm hooks into pandas methods directly
 
10:15 PM
Hello World of the day:
class Parent:
    def __post_init__(self):
        print('Hello world')

@dataclasses.dataclass
class Child(Parent):
    pass

Child()
 
Is that surprising because the post init is defined on the non-dataclass parent?
 
Surprising may be a bit of a strong word. I'd say it's not clear what should happen. Currently trying to figure out if this is documented
 
no, it's probably just a thing
@Aran-Fey why is it unclear?
 
Knowing dataclasses, there's probably at least 1 edge case where my __post_init__ suddenly stops being called
 
there's some extensive explanations cocerning this, looks well-defined enough
> The generated __init__() code will call a method named __post_init__(), if __post_init__() is defined on the class. It will normally be called as self.__post_init__(). However, if any InitVar fields are defined, they will also be passed to __post_init__() in the order they were defined in the class. If no __init__() method is generated, then __post_init__() will not automatically be called.
I'm not sure how it could come into play whether the method is inherited
 
10:19 PM
"if __post_init__() is defined on the class" is some vague weasel-word stuff
 
or perhaps it's just trying to avoid referring to self.__post_init__() because assigning the method to an instance wouldn't work
i.e. "type(self).__post_init__() exists"
 
Either way, it stops being called in case a subclass defines its own __post_init__, which - surprise, surprise - once again makes dataclasses unsuitable for my use case
 
> The __init__() method generated by dataclass() does not call base class __init__() methods. If the base class has an __init__() method that has to be called, it is common to call this method in a __post_init__() method:
well at least that ^ is also spelled out
@Aran-Fey just blame the kids
 
10:48 PM
Who let the kids develop the python stdlib, smh my head
 

« first day (4546 days earlier)      last day (402 days later) »