« first day (3380 days earlier)      last day (1792 days later) » 
00:00 - 21:0021:00 - 00:00

00:01
Someone posted a constructor like this (in an answer, not a question), then someone asked what the point of that **kwargs is, and then people started giving weird explanations instead of the obvious "there is no point, don't do that"
def __init__(self, breed="", color="black", size=5, mood="happy", **kwargs):
    Dog.total_dogs += 1
    self.breed = breed
    self.color = color
    self.size = size
    self.mood = mood
Blind leading the blind \o/
But hey, the upside is that I spend a lot more time with my own code now. Since that's my best source of not-awful level code
If you ever want to read mediocre code you know where to find my AoC
unfortunately I can't read numpy though :P
*fortunately :D
wim
wim
00:23
@AndrasDeak love the docstring too
x = 1  # set x variable to 1
 
3 hours later…
03:39
x : int = 1 # set x, an int, equal to 1
04:09
so SO, i gotta q. i've asked a couple questions where the answer just turned out to be some user error on my end (e.g., typo). should i go ahead and delete these questions or do they serve some purpose staying up?
@Aran-Fey why not **kwds. *args, **kwds is nicely balanced. /just-an-aside
user3064538
Does anyone know a better answer to this question? stackoverflow.com/questions/46962065/…
user3064538
basically how do you reuse args in subcommands using argparse

`./myscript.py do_bar 2 --quiet`

and

`./myscript.py --quiet do_bar 2`
05:12
@AlbertHan Usually these kinds of questions (typos especially) will get close-voted, but if you wish to close them yourself, go ahead.
@AlbertHan if others havent voted to close them, yes, you should
06:08
@alkasm @PaulMcG ty
06:34
@AlbertHan np. unfortunately "closing" seems like a negative thing, but really a major purpose of closing Qs is cleaning up the site to help people find more relevant information quicker.
06:49
/hi
Hi
07:25
cbg
 
1 hour later…
08:41
@Plain_Dude_Sleeping_Alone hello. Please don't post images of text.
@AlbertHan to add to what the others have said: you shouldn't self-delete questions with answers on them because this counts against you in a question ban. Closing is fine, and the community can delete them if necessary.
08:59
@wim without spamming the channel too much, I can recommend this blog for how obvious goroutine+channel patterns lead to incorrect/unextendable code.
09:17
cabbage
09:29
hey guys
I am playing around a bit with checkboxes in tkinter, and i made something that is working, but might be unnecessarily complicated
def test_states():
print(pll_state.get(), hwid_state.get())
x = pll_state.get()
y = hwid_state.get()
if x == 1:
States_List[0] = 1
if y == 1:
States_List[1] = 1
print(States_List)
i am getting the state of each checkbox ( in this case i have 2, i will need about 8 though), and if is 1 i pass it to a list which i filled with 0's, so if it's 1 i replace the 0
then i will take that list and for each 1 in it i will run a different function
can i make it simpler?
def test_states():
    states = [pll_state, hwid_state]
    states_list = [state.get() for state in states]
09:51
dang how do i format like that?
thank you for answering, the issue with that is that i can't pick the exact list index i will need in order to run the correct function
Hmm? Why not? In fact, why do you need this list of 0s/1s in the first place?
Dec 22 '19 at 22:41, by Andras Deak
@Jason please see our code formatting guide for chat and practice in the sandbox if necessary
ok my idea is that, the user will use the checkboxes to choose a number of tests, and then 1 button, to run the selected tests
each test is a function
so i thought that if i pass the 0 and 1 in a list in a predefined index, and then read this index in order to run the function of each test
it would work
if each checkbox corresponds to a function, use a dict that maps checkboxes to functions
for state, func in {pll_state: test1, hwid_state: test2}.items():
    if state.get():
        func()
something like that
```
test
```
i can't open the formatting guide :>
1 sec
    def pll_state_result():
    if States_List[0] == 1:
        pll_test()
    else:
        pass

def hwid_state_result():
    if States_List[1] == 1:
        hwid_test()
    else:
        pass


def states_result():
    test_states()
    hwid_state_result()
    pll_state_result()
found it
so, shouldn't something like that work?
yes, but it's a heck of a lot of code
How would that be better than doing it with a loop like I showed you?
10:05
When I autogenerated test file for my Time class, Python also went ahead and created an _init_.py file for the autogenerated test file. What am I supposed to do with the _init_ file?
nothing, it's there to import files to one another
thank you for the help!
@Aran-Fey it wouldn't, mine wasn't even working properly, let me give it a try :>
@SebastianNielsen Could you elaborate on that? How is your project structured, where is that __init__.py located, and what are its contents?
It's located in a folder named test. PyCharm autogenerated no content for the file, in other words, _init_.py is empty.
I guess this is the use case though: stackoverflow.com/a/43733357/7123519
It is just supposed to be empty
Still kind of weird why I have to have an empty init file ... I mean, what's the point if it's empty.
Hmm, what test framework are you using? I have no experience with unittest, but with pytest you usually don't want to have an __init__.py in your tests folder
I am using unittest
But it's so easy to use unittest, and it does the job in few lines of code.
10:16
Maybe unittest needs to import your tests folder, not sure how it works under the hood
cbg guys
@SebastianNielsen A directory with an __init__.py is a regular package, while a directory without an __init__.py is an implicit namespace package
anyone come across a module that converts an error to json?
Converts an error to json how? How do you represent an error as JSON?
10:24
as a json object? seems quite simple? what am i missing?
not exactly sure what you're asking, unless you mean a way to just supress an error, catch it, and make a dict-like or json-like object out of it. If that's the case, just roll with your own solution. Only, don't just supress any error and leave it be, that generally isn't a good idea.
So like {"type": "ValueError", "message": "whatever"}?
yeah basically
in NPM i have this available to me: npmjs.com/package/jsonify-error
I don't know any modules that can do that, but converting an exception to a dict like that only takes about 3 lines of code. The more difficult part is converting json back to an exception. If you don't need to do that, just roll your own jsonifier
10:42
i don't need to convert back
at least right now
    File structure:

    __init__.py
    modules/
        Time       # File named Time that contains a class named Time
    test/
        TestTime # I want to import the Time class here

    Here is my attempt:

# Inside TestTime
from Time import Time   # How do I import only the Time class ?
So that I don't have to write Time.Time all the time
Something seems off about your filestructure here. Why is there an init up top, but no inits inside? Also, you essentially need to name this "top level folder" where you';ve placed the init, and build absolute imports from that point.
22
A: How to import a Python module from a sibling folder?

David WoleverThis is happening because A and B are independent, unrelated, packages as far as Python is concerned. Create a __init__.py in the same directory as Driver.py and everything should work as expected.

this is why there is an init in the root folder ^^
im not worried about the init in the root folder, but the lack of inits inside. (unless you have them there as well as didn't specify)
Uh, well, I did actually have an init inside the test folder
but not in side the modules folder
But why would I put an init inside the modules folder?
10:51
because you want it to be a package?
Well, I don't want the modules folder to be a package
refer to your own linked QnA as well, see their structure
I need the root folder to be a packager in order to refer to sibling folders
and there is an init in the test folder for unittest reasons
@SebastianNielsen this doesn't make sense if the components inside don't get grouped. Put inits on every level, unlearn your assumptions. (and completely forget about implicit namespace packages for now)
Okay, but how does this help me ?
10:54
refer to my first statement for that part. you build absolute imports from the root level.
so, from rootfolder.Time import Time.
or you can use relative imports too at that point, but eh.
either ways
@Aran-Fey what's the easiest way to convert an error to a dict?
Actually I cant do relative imports:
from ..modules.Time import Time

# Error: attempted relative import beyond top-level package

The reason, if I understood this correctly, is that ..folder is only allowed within a package?
I can't do an absolute import either, so this wouldn't work:

from myRootFolderName.modules import Time
Error: "No module named myRootFolderName"
11:11
cbg
11:38
@Jarede {'type': type(err).__name__, 'message': str(err)}
I really need to write that "how to correctly structure your project and make it importable" post sometime
seeing how no actual experts are doing it for me
my_project/
    .git/
    docs/
    my_projects_root_module/
        __init__.py
        project_stuff.py
    tests/
    pyproject.toml
That's how your project should look, and in order to make my_projects_root_module importable, you should install it in some way or another. Be it python setup.py install --editable or dropping a symlink to it into your site-packages or whatever floats your boat
Actually,

from modules.Time import Time

Did the job
I didn't have to declare the rootFolderName or anything
11:56
@SebastianNielsen The __init__.py doesn't have to be empty. But the primary use-case for that is to improve usability, which most people don't need at first or ever.
@Aran-Fey
```
output = "{}: {}".format(type(err).__name__, err)
exc_type, exc_value, exc_traceback = sys.exc_info()
error_details = {
"error": output,
"exc_traceback": traceback.print_tb(exc_traceback),
"exc_value": str(exc_value),
"exc_type": str(exc_type)
}
```
You'll probably want to change exc_type to str(exc_type) and exc_traceback to traceback.format_exception(exc_type, exc_value, exc_traceback)
12:23
oof, I meant exc_type.__name__ instead of str(exc_type)
12:50
Could you please tell me how I can correct this
def findclub(x):
    return x[x.find("("):].replace("(", "").replace(")", "") if str else x
raw_data['CLUB_DEBUT'] = raw_data['CLUB_DEBUT'].apply(lambda x:findclub(x))
AttributeError: 'float' object has no attribute 'find'
convert your floats to strings before you call findclub on them?
13:12
 raw_data['CLUB_DEBUT'].fillna("0000", inplace=True)
yeah
Ha! So I gave @ruben.lfdz an assignment, and even a google link to follow to find the solution for himself, but still comes here asking for the answer?
@PaulMcG rear view mirror needed twiddling with :p
I gave him this, and told him to find out how to fill in the blank:
def finder(x):
    return x[x.find("("):].replace("(", "").replace(")", "") if ______ else x
It's also a horrible use of apply (even if we ignore the pointless lambda)
@Paul well... if str is filling out the blank - it's errr... just not useful :)
Almost seems a really weird way (and I'm guessing on what's needed here) of writing raw_data['CLUB_DEBUT'].astype(str).extract(r'\((.*?)\)') or something
13:23
@PaulMcG Sorry I thought you left the chat, thanks for your help I sorted it out
@Martijn it's quite funny when I read the response for that flag I raised on MSO... I immediately thought: "yup - that's Martijn" :p
@wim oh good point, been so long since I worked with 2.x. @PaulMcG I see, I was hoping for some voodoo magical unicorn code ;)
13:43
@JonClements drat, are my peculiar grammar choices giving me away, are they? :-P
haha... that and 4.5 years of seeing your replies :)
@MooingRawr saving that for later
13:58
bbiab
14:19
A recent question asks "how do I get the largest value in a list?" and the most upvoted answer recommends using numpy
Shocking. Would have expected pandas.
Pandas too.
Hi all
value in what term? numerical ?
14:22
Granted, the numpy solution is rather nicer looking than the vanilla solution.
Does anyone have an idea of dash plotly
3
Q: Get highest duration from a list of strings

Rafiul SabbirI have a list of durations like below ['5d', '20h', '1h', '7m', '14d', '1m'] where d stands for days, h stands for hours and m stands for minutes. I want to get the highest duration from this list(14d in this case). How can I get that from this list of strings?

also Kevin, did u ever get a solution to your directional graph problem?
Nope.
In the time-honored tradition of programmers everywhere, I'll probably leave it half finished for all eternity
boo lol ;( summon me when you get a solution :D
14:24
Sure, but don't hold your breath. Once I lose steam on a concept, 99.99% of them I never ever go back to.
Hello Im new to chatrooms lol i never knew they existed in Stack Overflow XD
They don't advertise us very prominently, no
ok cya guys
o.o okie....
Does anyone know a suitable place to ask a better algorithm for a problem that I can solve with slower algorithm? I guess code review considers only optimizing current code. The code I found is available from the Internet but I have no copyrights for it.
14:36
Do you have to have the copyright for a piece of code in order to ask about it on Code Review? I didn't know that was a requirement
@Kevin I would have thought not - provided you don't claim ownership/authorship - although SO might have their own lawsuit insulating requirements.
@Kevin I don't know about copyright, but you can't ask for review on someone else's code.
If none of us know for sure, there's a pretty good chance that nobody at Code Review knows either, and they'll just review the code without complaint.
@Kevin I would not be surprised if someone googles the code that the OP posts and accuses them of copying.
I am wondering how would they prove that it is not just a co-incidence (that OP's code is same as that googled link)
14:40
... Are we talking about the same community of programmers here? Virtually the entire user base copy-pastes solutions straight from Stack Overflow, often with zero attribution.
Yeah, but codereview has higher standards :P
eh, if you can reason about your own code/code copied off of the webs, you're in a good shape imo.
at that point, do whatever really.
@anky_91 Well, this isn't a court of law, so they don't have to prove anything. They can just say "-1, looks copied to me"
@ParitoshSingh slippery slope dude.
Right, then how does copywright matter anyways :)
14:44
@Dair wheeee. ;)
> If you can answer "yes" to all of the following questions, then your question is on-topic for Code Review:

[...]

Am I an author or maintainer of the code?

For licensing, moral, and procedural reasons, we cannot review code written by other programmers. We expect you, as the author, to understand why the code is written the way that it is.
Ok then.
Turns out that looking in the FAQ answered my question faster than having each of us speculate about what the FAQ might say
Yeah, that sounds perfectly reasonable to me.
@ParitoshSingh That is no my code but the problem is available from the internet, someone has posted a solution, and someone else said there is a faster algorithm. I just like to think what kind of trick solves the problem faster way.
14:45
@Kevin I literally said this lmao
@JaakkoSeppälä but what about the algorithm itself that's posted there? are you comfortable with it, and able to reason about it?
Also, might be a fun activity if you try to find out a faster method yourself before opting for a review
@Kevin Maybe this is the real goal of stackoverflow - train an AI to respond to input of requirements ('questions') and return production code ('answers')...
@ParitoshSingh Well, I'm quite happy with the current solution. But I would like to learn the trick that makes the code faster. Maybe I just have to think more.
That sounds like a no to me.
morning cabbages folks
14:54
cbg
stackoverflow.com/questions/59789754/… makes reference to a "ShortHand ternary" e.g. msg = output or "No data returned". I suspect that name was made up by the tutorial author but I'm prepared to discover that it's buried in the official docs somewhere
Currently slogging through docs.python.org/3/… to find out
15:10
well, if "ternary" refers to the ternary operator, a la <cond><value when true>:<value when false>from Java/C++, then msg = output or "No data returned" is not shorthand for that, since it very much relies on the boolified value of output. Further, the or makes it look like output should be a bool (because or is a logical operator), when it fact it won't be. I'd even argue that this makes code less readable
> I suspect that name was made up by the tutorial author
I've seen it happen far too often that people who don't fully know what they're talking about (like myslef) but don't always know it (unlike myself) make up real-sounding bogus terminology. This includes TAs that I've worked alongside of, in the past
@Kevin there's nothing ternary about that, is there?
The author also says the syntax was introduced in 2.5. I wonder if they just pulled that number out of thin air, or whether there's some truth to it. Did or not exist in 2.4? Did or exist, but refuse to work on non-booleans?
@AndrasDeak tern-minus-one-ary
:48361168 well, it's equivalent to msg = output if bool(output) else "No data returned", so I can understand why someone might want to call it shorthand for a ternary. But it's nowhere near as powerful as the ternary operator and calling it a shorthand ternary is like calling a namedtuple a shorthand class
yeah, i find "short circuit" a much more common term for that kind of situation
and truthiness. It's a 1 2 combination
Actual real ternary expressions were introduced in 2.5... I guess the author read "the specific syntax a if b else c was introduced in 2.5", decided that a = b or c was effectively the same, and assumed that was also introduced in 2.5
15:16
@ParitoshSingh but we're talking about assigning values, not stopping the evaluation of a condition. Does that still count as short circuiting, then?
@inspectorG4dget why shouldn't it imo? Whatever you do after evaluation is all "extra". Just like the use of lambda, or assigning the result, neither should have any bearing on what's going on in the expression itself
The core mechanism in question should still be referred to by what it's doing in isolation against how we use it later. In the sense that it's a smaller block to explain to someone and to work with
@ParitoshSingh that's a good point. I withdraw my objection
@Kevin got it fixed yesterday. With all of it running, the buffer was filling up on the serial line. Had to flush the buffer line after each read and now we're good.
👍
15:24
@AndrasDeak Thanks Andras, I remember seeing that, and I reiterated that advice also
Also Kev: thanks for helping out yesterday. Ultimately it led me to the right direction to fix the issue :)
@PaulMcG I know, I followed your struggle from afar. I applaud your patience, I just wanted to make sure it's not wasted
15:36
rm -rf gonzales
oops! this isn't my terminal
user6568562
Cbg everyone
cbg
🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬
There Will Be Cabbage
15:52
I do not know with what weapons World War Three will be fought, but World War Four will be fought with cabbages
16:13
make peace cabbage, not war cabbage.
So some church said that the world was going to end this year or next year due to our dependency on plastic by burrito wielding space lemurs. Lemme see if I can find it
I bet they have cabbage in them
Sorry, it isn't until 2047. Church of BLAIR had the prediction. Kinda funny to look up.
16:36
The more I work on my own projects, the more I'm convinced that skill in programming has little to do with the text in our files, which is mostly elementary and straightforward enough, but everything in how we architect and organise said code and files.
well... in the end it's still text in files though
Programming is the art of knowing when to use 0, and knowing when to use 1. All else is ornament.
16:51
If we have a dupe target for "Q: why doesn't re.match match this string? A: you should use re.search instead", then stackoverflow.com/questions/59791593/… could use it
what if re.search fails due to a "computer unplugged" issue? Could you call for a re.match?
17:15
Hmmm so matplotlib/Pillow won't install on Win 10 py -3.8 with pip 19.3.1, but will with pip 19.3.0. That's not ideal.
I suggest switching to linux
haha, that would solve the problem too!
@AndrasDeak Well sure, but while I'd love to go ahead and install linux on my wife's employers machines, I don't think that would be well received.
I'm surprised that pip would break its own backwards compatibility
17:22
then I suggest switching to 3.7...
cbg
got stuck on the way to work and almost didn't make it
I have pip 19.3.1 and Windows 10 and Python 3.8 and I'm tempted to uninstall pillow to see if I can replicate the problem. But I like Pillow and don't want to make it un-installable
virtualenv (venv)
wait...you installed pillow globaly?
I install everything globally.
17:26
windows has no system python so it's not such a huge deal there, I imagine
It complained about not having some dependencies zlib I think for Pillow when installing from the commandline, 'pkg_resources.extern' when using Pycharm's feature that upgrades env dependencies, and matplotlib needed 'ft2build.h'.
@Kevin I'm the opposite. I virtualenv everything. Even for trivial stuff like aoc.
If a library is good, I want to have access to it from anywhere. If a library is bad, I won't install it to begin with
I have a few things installed globally, but all my projects have venvs that pycharm kindly helps in setting up.
Ok, I tried using venv and I was able to install pillow. But I notice it's using cached whl files, so I don't know if this counts as being installable on a totally fresh environment
I'm surprised that the virtual environment was able to check my global environment for cached files. I guess it's more interested in stopping local-to-global transmission, not the other way around.
I'll try again with --no-cache-dir specified... Successfully installed pillow-7.0.0 ¯\_(ツ)_/¯
17:38
TIL .ninja is a TLD
Maybe we're using different architectures or something? I'm installing Pillow-7.0.0-cp38-cp38-win32.whl
or perhaps the esoteric issue has to do with something else
I feel like I've had zlib-related frustrations before, although I forget if it was specific to pillow
wim
wim
@Kevin It existed in Python 1
Python 1.0.1 (Feb 23 2019)
Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam
>>> 'a' or 'b'
'a'
>>> '' or 'b'
'b'
I couldn't be bothered to check any earlier
I suspected it was a venerable old feature. So the tutorial author is pretty befuddled, then
17:42
@Kevin I'm running 64 bit, so Pillow-7.0.0-cp38-cp38-win_amd64.whl
It's not even a matter of him thinking that ternary and "ShortHand ternary" were introduced in the same version, because he claims that ternary was introduced in 2.4 (wrong, AFAICT) and ShortHand ternary in 2.5 (not even wrong)
wim
wim
also, fish slap for installing everything globally.
And I have a vague recollection some of my googling found issues specific to 64, but I didn't actually find my specific combination of version and issues.
wim
wim
bad Kevin!
Oof <I take 2d4 slap damage>
@toonarmycaptain Just switch out your amd processor for intel, problem solved ;-)
17:47
@Kevin Oh ok, sure.
Easy and fun and nothing could possibly go wrong
wim
wim
how do useless peps like this keep getting accepted python.org/dev/peps/pep-0591
@wim because people want to turn Python in Java it seems
it would be easier to have from __alternate__ import java
I'm waiting for public static void
wim
wim
seems kind of a U-turn on "consenting adults" philosophy that python historically had
e.g. you just define a normal variable and then you don't reassign it , viola, it's a "constant". your language remains simple and without feature bloat.
17:58
"We're all adults here" is the most neglected of the Python philosophies, I feel. It's not even in import this.
Trying to figure out if it even shows up in the docs... I see github.com/realpython/python-guide/pull/524/… but I don't know where it lives on the site, if anywhere
it's a controversial phrase so you will probably not find it anywhere official
it both excludes kids and subtly implies that people who get bitten by language features (or lack thereof) are not adults
at least it's not "we're all consenting adults" :P
Oops, that diff log isn't from the CPython repo... Darn these crazy eyes of mine
wim
wim
it's a metaphor. geeze. you can drive yourself insane with this level of self-censorship
docs.python-guide.org/writing/style/… is where "we're all consenting adults" used to be, before it was removed for being #Problematic as Andras indicates
Sam
Sam
Hey all, anyone here have experience in the NLP domain? Word embedding models such as Word2Vec are trained on a vocabulary and somewhat lacks sentence context. You can attempt to capture the semantics by stacking these word embeddings into a sentence and performing a 1 dimensional convolution over the resulting embedding matrix.
Models like BERT however capture the sentence context in individual word tokens so I was wondering if it theoretically makes sense to still apply a convolution over such word embeddings or if that operation becomes somewhat redundant?
18:08
given a dataframe of n rows, what's the best way to assign the following list [1,2,3] to a column and have it repeat the length of a df?
Hmm, can't say I know anything about convolution, despite nearly all of my projects becoming convoluted eventually
np.tile
I've done some NLP in the past (before word2vec was invented). I'm passably familiar with the word2vec theory, but I must ask whether your premise is accurate. As I understand it, word2vec is trained on a corpus to learn a word embedding from sentece context. Could you please tell me where I'm wrong?
or resize
l=[1,2,3]
np.resize(l,10)
#array([1, 2, 3, 1, 2, 3, 1, 2, 3, 1])
np.tile is perfect thanks anky
wim
wim
18:10
What do we think of late answers that just come in and say "you can also <same thing that other answer shows>, but with f-strings!" ... downvotable? harmless?
@Datanovice no problem
I don't like answers that add little substance, but I do like raising awareness of string formatting options that are less than ten years old, so for me it balances out to "do nothing"
Sam
Sam
@inspectorG4dget I dont think Word2Vec handles context. You'll obtain the same embedding vector for Apple regardless if the sentence is talking about the fruit, or the company
@Datanovice there is also a way using islice with cycle from itertools
wim
wim
so they will become downvotable in 2026, then?
18:13
but thats slower
@wim Yes, once f-strings are passe' and direct DWIM brainscans become the mainstream style
@anky_91 hmm, using np.tile gets me close, but dividing my array by the max value in the range (len(df) // len(my_range)) it gives me one less row than my dataframe
len(my_range)+1 ?
cant guess without a small example, may be other can :)
i'll ask a question
did you try resize though?
18:23
@anky_91 yes
ok check this
18:35
@anky_91 that solved it, thanks!
howdy. anyone know a good multi-class dataset aside from iris?
ideally something with between 3 - 12 classes
@wim I think new syntax etc does deserve new answers/edits. Full disclosure: My current best answer is a Display a float with two decimal places in Python, although the top two answers use .format and % style syntax.
numeric features?
I'd look at UCI machine learning datasets or Kaggle. Were I less busy at work right now, I'd be more helpful
yes, non image =)
thanks mate. i'll check it out
looks binary
as with most phenotypic datasets that dont have disease subtypez
see this seems like theres 2 there that fit the bill
18:50
@Datanovice no problem
LOVE THAT GUY
that blog series is an asset to mankind
i agree :)
Abalone (from Spanish Abulón) are shellfish, a genus of gastropods.
19:08
vveird, people use classification on this to predict discrete # of rings. surprised that's not more of a regression.
Is there a fundamental difference? Isn't classification just curve fitting to a discrete-valued function?
@HashRocketSyntax im sure you can treat it either ways really
And if you want it to be treated more like a classification problem, you could perhaps bucket some number of rings together too
I wish i had a sound enough background to be able to interpret your comment and give a response that could do it justice AD.
On the contrary; you have way more background than I do. That's why you can't answer :P
random guy: the textbook I'm currently reading has a cahpter/section on how to turn a regressor into a classifier... mostly with thresholding
i appreciate that interpretation, however overly kind it may be :P
@inspectorG4dget aye, there's also the logit function, which is essentially how logistic regression came to be.
thresholding with the logit function works very nicely together to use essentially regression for classification
wim
wim
19:36
@toonarmycaptain ok. In that case it's pretty welcome - I think there should definitely be one on popular highly upvoted questions like that one. It gets a bit repetitive to have an almost-dupe answer on every string formatting-related question though. If you know how to use str.format spec then you pretty much know how to use f-strings too.
I also object to your claim that new code should prefer f-strings as as f-strings "are much faster".
@wim I thought they were (due to an Antti pattern)
Is there an alternative to numpy.quantile that works with multidimensional quantile specifications?
e.g. I have a 3D array of values and a 2D array of quantiles, and I want to take those quantiles along the first axis.
I would expect f strings to be about one function-name-lookup faster than the equivalent .format call
wim
wim
how often is string formatting your bottleneck??
@user76284 are you sure it doesn't work like that already?
19:40
Never, but we've never let practicality get in the way of a good argument about speed before
wim
wim
there are reasons not to use them also (e.g. it's too premature to drop support for python 3.5, 2.7 ...)
i just like reading f strings a lot more than older formatting methods
wim
wim
yes, usually they are more readable, but not always.
aye, exceptions to every rule and so on
I am forever on the side of "optimize when you discover a bottleneck, and no sooner" but I'll still inspect a dis.dis call for the thrill of it
19:41
@AndrasDeak Yes.
I tried it.
hmm, the error is very weird
wim
wim
@AndrasDeak to be clear, I'm not objecting to the claim that they're faster. I'm saying it's a big jump from there to "new code should use them", there are several more important things to consider than optimization here.
ah, OK, misread your emphasis
wim
wim
you may as well say "new code should be written in C extensions, as they're much faster"
@user76284 it would seem that the quantiles just get flattened
19:44
import numpy as np
a = np.random.randn(100, 200, 300)
q = np.random.rand(200, 300)
np.quantile(a, q, 0)
This throws ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s).
it gets "better" if you inject a leading singleton dimension in q with [None, ...]
np.quantile(a, q[None], 0) throws ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 1 has 1 dimension(s).
yeah, whereas it has 3 dimensions :|
oh nevermind, that's also the original error
guess I managed not to read that twice, sorry
@user76284 sorry, I don't know
but percentile has been there much longer so perhaps it's more likely that there's a broadcasting replacement for it
The way I usually use numpy.quantile (which works) is by taking an array a of shape (n1, n2, n3 ...) and an array q of shape (k,) and it returns (for axis=0) an array of shape (k, n2, n3, ...). So it's meant to do something different, namely apply the same quantiles from the q array to the entire a array.
While trying to write a program that would trace out the shadow of a cube rotating along an axis passing through opposing corners, I found math.stackexchange.com/questions/115743/…, which contains exactly the image I sought to produce, but better. I guess I don't have to actually write the program now.
19:50
@user76284 indeed
But now I want to take axis-wise quantiles.
Guess I'll have to write the function myself.
@wim 3.6 seems like a good compromise between feature set and backwards compatibility. Even our ancient science machines have 3.6 almost out of the box these days.
Writing all these utility functions which numpy lacks makes me nervous.
@wim That's a fair cop. Is "are much more readable, in addition to being faster." less objectionable?
20:05
I'm sure some SO answerers can give you examples where an f-string is not more readable
"generally", then?
yeah, if you do crazy things inside of your string it quickly becomes a mess
usually?
and "much" opens the door to bike-shedding arguments about how much "much" is
A C programmer will probably prefer percent formatting
If you don't want to embed crazy expressions inside your f-string, just do (lambda x, y, z: f"{x} {y} {z}")(<crazy expression 1>, <crazy expression 2>, <crazy expression 3>), easy
20:09
IMO the selling point of f-strings is convenience, not readability
I think the two are related
I mean...I'm sure you can use strings of 1s and 0s and eval etc to define and run classes and functions...if you want to do foolish things, python generally lets you.
The best reason to use .format is when you're halfway through writing a string constant, and you think to yourself "ah hell, I need to parameterize this" and you can't be bothered to go back and put an f before the opening quote mark
and templates can't be f-strings
Once f-strings can be indicated with an f suffix, it's all over for .format
20:13
haha
wim
wim
@toonarmycaptain I dunno, I don't think you should say they're preferred. Because they're not, always. You can say they're "often more convenient and readable" but it's a bit opinion-based and case-based whether they are preferable.
stdlib logging should still use % formatting, for example, because there are significant benefits to the formatting being "lazy", and f-strings will always be eager.
IIRC logging allows for .format and $ templates as well.
f strings require a lambda to be lazy, which is kinda ugly :/
wim
wim
@MisterMiyagi only for the log format itself. the event formatting is always %-formatting.
@wim Ok. I believe I took that term from a few places. PEP501, realpython to name a couple of top hits from google.
good old % formatting. <3
@toonarmycaptain well, various PEPs declared %-formatting as good as dead, yet here we are...
wim
wim
20:24
if it ain't broke, don't fix it
I did say for new code lol, but I changed it to "I prefer".
wim
wim
does your prompt really have no whitespace between the >>> and the input ? that's weird
20:47
@wim Not today. But I made that answer awhile back. So it's plausible, but more likely I cut and pasted and it didn't take the prompt so I added it manually, neglecting the space.
00:00 - 21:0021:00 - 00:00

« first day (3380 days earlier)      last day (1792 days later) »