« first day (4539 days earlier)      last day (408 days later) » 

9:42 AM
Cbg
 
10:41 AM
duplicate, some sort of "pass by reference" question stackoverflow.com/questions/75800021
 
11:04 AM
I have searched all over the place, but I haven't found an answer. I'd like to perform addition on a single column in a pandas dataframe. I'd like to add the value 2 to all values in a specific column. Grateful if anyone can help.
 
df['my_col'] += 2?
 
@roganjosh thank you! so simple :)
 
11:21 AM
being able to do that sort of thing is half the point of using Pandas in the first place.
Examples like that should have been front and center in anything that tried to tell you that Pandas exists.
 
11:58 AM
@AndrasDeak--СлаваУкраїні I imagined as much, I just wondered whether there was an angle to have a bit of fun before I go; thanks for putting some thought in. In my mission to avoid them introducing black I would probably have to write a full roganjosh linter, which might be a bit beyond me and reason :P
This is one of the most bizarre design choices that one of my colleagues ran into today. Why on Earth would you want datetime.now() to be evaluated only once when you start a web service? By their very nature they're going to be long-running processes
 
Doesn't look like it was their "choice".
 
I mean it was Dash's choice
The only thing I can think of is due to their bindings to React components that mean it has to be explicitly updated through a callback.
 
12:26 PM
Why would you expect objects to be randomly implicitly updated
When would you expect that update to happen?
 
When I refreshed a page? I wouldn't expect to have to register an explicit callback function to handle giving fresh date data to a widget on a page load?
Without the callback function, it'll forever load the date that the server was started. Why should that date be bound to the widget rather than giving it a callable in the first place?
This means that even new users to the site would get the stale data on their very first visit, which could be N days out of date
 
If you know that your data is gonna get outdated you should handle the update yourself imho, not only when user requests it.
Delaying the update until the request might increase load time significantly
I've got a POC app that gathers information from several apis and it simply asks each one every minute, regardless of any clients using the app. This way the page loads near instantly instead of waiting for response from each api
 
Except the only sensible thing to do with a widget specifically designed for selecting dates has to update on every page load. Otherwise you're suggesting that it's useful to have a calendar widget telling me it's 01/01/2023 every time I reload a page for performance reasons on the server's side
I'm not suggesting the field gets dynamically updated on a page without refreshing. This date is permanently fixed on the date that I start the server and won't naturally update on any page refresh or a new page visit
 
12:42 PM
Run an Interval that changes current date server side every day
 
That's what has to be done. Now you'll need to explain to me what a day is because there's at least 23 other timezones that are going to disagree
 
You can actually do what you want out-of-the-box: dash.plotly.com/live-updates#updates-on-page-load
Make initial layout a function not an object
 
Every other such widget I have seen in the past would just handle the date loading client-side and you could specify the number of days for a window to be valid. That's no burden on the server
 
 
2 hours later…
2:42 PM
For one of my libraries I've had some issue tickets about type checks failing in use. So far I've relied on just typechecking the library and unittests, but apparently this isn't enough.
Is anyone aware of a way to do "type unit tests"?
 
user17135505
2:54 PM
Howdy, do you know if possible to chain n times?

files = [1,2,3]
obj.method1.method2.method3(1).method3(2).method3(3).method4
 
user17135505
In case above, i would like to

obj.method1.method2.trickery(files).method4
 
Python generally discourages chaining so there isn't any syntax support for this.
You could probably reduce or use a helper, but I doubt it'll look any better.
If you are just concerned about not knowing files beforehand, rolling it into a loop seems appropriate.
state = obj.method1.method2
for file in files:
    state = state.method3(file)
state.method4
 
user17135505
3:11 PM
Thanks @MisterMiyagi, this has worked and was surprisingly easy! (The underlying library makes use of method chaining.)
 
Has anyone ever heard of "heavy API" saw a job posting for a python dev role and it mentioned "Heavy API - with REST or JSON" I couldnt find anything clear on the term heavy api.
 
3:22 PM
The opposite of FastAPI maybe?
 
3:33 PM
I am trying to create different datasets, and this case the following code is used to create a sorted sequence based on a bunch of parameters:
np_type = np.uint64
n = 10
max_value = np.iinfo(np_type).max if issubclass(np_type, np.integer) else np.finfo(np_type).max
min_value = np.iinfo(np_type).min if issubclass(np_type, np.integer) else np.finfo(np_type).min
arr = np.linspace(min_value, max_value, n, dtype=np_type)
np.around(arr).astype(np_type)

But it gives to me:
RuntimeWarning:

invalid value encountered in cast
 
3:46 PM
@reuseman numpy version?
look at linspace(max_value, max_value, 1, dtype=np_type) first and understand it (I don't)
There might be an accumulator under the hood that overflows
 
This works without error for me.
Numpy 1.21.2.
FWIW, for this specific example of using ints I don't see the point in the last operation.
 
Same. But they have a warning. And note the non-monotonic results.
 
I also get a 0 as last value.
 
Newer numpy probably warns of the overflow
@MisterMiyagi not very linspace-y, is it?
 
Hey, I've seen worse from you data folks!
 
3:52 PM
1.8e19 becomes 9e18 in linspace
 
That would be a kickass line in some sci-fi flick.
Prepare to enter... the linspace!
 
@MisterMiyagi I am using 1.24.2
 
I assume there's a (max + min) / 2 in there
 
Indeed np.linspace(min_value, max_value / 2, n, dtype=np_type) seems fine.
 
I don't get why it should be max_value / 2, though. What's the problem with just max_value?
 
3:55 PM
@AndrasDeak--СлаваУкраїні / (n + 1), that is
 
I'm not entirely sure where overflow comes into this.
min_value is just 0 in this case.
 
@reuseman linspace has to compute a step. And must do this nontrivially to minimize floatberrors.
There's probably a large comment somewhere in the implementation
 
Uhm, ok then I will go with the max_value / 2 trick, thanks!
 
Interestingly enough, max_value - 2**10 is fine as an upper bound.
np.linspace(min_value, max_value, n, dtype=np_type, endpoint=False) works as well.
 
@MisterMiyagi probably depends on n
 
@AndrasDeak--СлаваУкраїні Possibly, but I guess in practical case (== those that fit memory) the end is then always far away from overflow.
 
Possible, I haven't really given it thought
 
@roganjosh Eerie! 😱
 
That's "eerie" with two "e"s
The Scary Door
 
 
5 hours later…
8:46 PM
@roganjosh That sounds like something from The Goons: What time is it, Eccles?
 
 
2 hours later…
10:57 PM
dict2 = {k:[-1 if i == "No corresponding block" else i
            for i in v]
         for k,v in testdict.items()}
 
the above is sort of hard to read because k, i, v are mentioned before they are defined
 
that is not why it's hard to read
 
is there an alternative to make that readable?
 
yes, not put a messy list comp like that in a dict comp
 
10:58 PM
you'd just use a nested for loop?
 
one loop and one list comp perhaps
even without changing the logic you can format it as
dict2 = {
    k: [
        -1 if i == 'No corresponding block' else i
        for i in v
    ]
    for k, v in testdict.items()
}
 
that's prettier already. it still bothers me that variables are getting mentioned before they are defined
 
But each comprehension needs mental gymnastics back and forth as you said, and the conditional expression at the deepest level is similarly harder to read. Just unpack all that. Nested comprehensions are usually a mistake.
@shintuku that's how comprehensions work
you can get used to that part fast
 
If you move the -1 if i == ...etc. code to a function, it might be a little cleaner for you (at the expense of some slightly slower performance, doing function calls instead of the inline if-else expression):
def normalize_to_int(x):
    return -1 if x == 'No corresponding block' else x

dict2 = {
    k: list(map(normalize_to_int, v))
    for k, v in testdict.items()
}

 or

dict2 = {
    k: [normalize_to_int(i) for i in v]
    for k, v in testdict.items()
}
 
that's definitely more readable
 
11:10 PM
just put the list-map version in a footnote :P
 
I just made up that normalize_to_int name not knowing your application, you can probably compose something more meaningful
@AndrasDeak--СлаваУкраїні Yes, I'm finding myself preferring [fn(x) for x in seq] over list(map(fn, seq)) these days.
 
yes, that's a lot more readable (and "pythonic") unless you ask functional programming fanpeople
 

« first day (4539 days earlier)      last day (408 days later) »