« first day (3131 days earlier)      last day (1817 days later) » 

8:00 PM
@ParitoshSingh lol, I just blurted that out.
 
@JoeSaad Something isn't adding up for me here
 
@Kevin can you explain that syntax you just wrote?
 
haha, okay phew. i was about to have a "moment"
 
@JoeSaad I was experimenting to see what "a list containing one float value, which is NaN" would serialize to when using json.dumps. I'm surprised that it becomes the string '[NaN]' because that doesn't look like strictly valid json to me.
I notice that json.dump and json.dumps have an allow_nan parameter, which you can set to False in order to make the code crash if you have any nan floats in the input.
 
> NaN cannot be represented in a JSON string; direct representation of Infinity is also not permitted
 
8:02 PM
@Kevin To the extent that json.loads(json.dumps([float('nan')])) works
 
the receivers would complain apparently. thats from jquery docs
 
wim
if you want to know what is valid json, don't ask stdlib json
it has all kinds of terrible "conveniences"
 
Well that's annoying. Why does json module allow that?
 
<redacted> Roganjosh op
nvm im slow
^^
 
wim
@Kevin how else would you disambiguate the float from the string "NaN" ?
 
8:04 PM
can i blame the lateness of the hour? :P
 
@ParitoshSingh perl could do something like that...
@wim isn't there a null in json?
 
Yes, there is
 
@wim I don't see how that's super's fault?
 
well, i dont think of it as bad or anything from the get go. Just, i would have been really surprised if i had never managed to encounter that style of writing break, and it existed all this while
 
But I'd say null was closer to None than NaN
 
8:06 PM
oh, right, None
 
yep yep
 
@JoeSaad I think what this debate is kinda getting at is that you'll need an MCVE so we can try help fix the issue prior to creating the JSON in python. You'll need a way to get rid of the NaN values, because it's probably not overly useful in just making Python throw an error
 
Hmm, I could have sworn there was a way to override the normal serialization logic of the json module. You can subclass JSONEncoder, but that only changes how it handles classes that aren't supported by the basic encoder.
 
No 3.x json docs on the first page of duckduckgo...
 
wim
toml ftw
>>> d = {
...     "k1": float('inf'),
...     "k2": float('nan'),
...     "k3": 0.1,
...     "k4": "0.1",
...     "k5": "0.1.2",
...     "k6": None,
... }
>>> print(json.dumps(d, indent=2))
{
  "k1": Infinity,
  "k2": NaN,
  "k3": 0.1,
  "k4": "0.1",
  "k5": "0.1.2",
  "k6": null
}
>>> print(yaml.dump(d))
k1: .inf
k2: .nan
k3: 0.1
k4: '0.1'
k5: 0.1.2
k6: null

>>> print(toml.dumps(d))
k1 = inf
k2 = nan
k3 = 0.1
k4 = "0.1"
k5 = "0.1.2"
note: k6 is omitted, which is the correct choice!
 
8:13 PM
The module seems to have some... rough edges. It's often not possible to encode a numpy array of ints, at least on Windows, because it defaults to int32 and it won't serialize that. You can do all your fancy numpy work but then you still need [int(i) for i in my_array_slash_series]
 
silently omitting something never gets into my good graces
 
uuuuh my_array_slash_series.astype(int)?
 
Nope
 
give or take .tolist()?
also I wouldn't expect something basic as json to correctly encode something as complex as numpy arrays
 
.astype(int) on Windows will make 32 bit integers
 
8:15 PM
@JoeSaad I don't think the json module has an easy way to filter out NaNs. You could filter them out yourself before calling dump. Example implementation: pastebin.com/WTRzjLCS
 
.astype(np.int64)...
 
wim
@ParitoshSingh pytoml will put a commented out line for it. but, really, just omitting it is better.
 
laziness plus windows use has its price
 
@wim i'd rather have it complain and fail out the gate, and perhaps have a flag to ignore.
 
wim
null / None should never really be used as a first-class value
 
8:16 PM
@AndrasDeak Sure, but now we're talking about it encoding into JSON things that JS can't decode.
 
@Kevin I guess you code override encode...
 
wim
@Aran-Fey whose fault do you think it is?
 
@roganjosh I'm not following
 
@wim Well, either yours for inserting a class that's not supported into the MRO or theirs for writing bad code that can't handle a class being inserted into the MRO. I tried to figure out why things go wrong there, but I'm not sure what's really happening
 
@AndrasDeak "throw out the numpy array integers, we don't want to serialize those. But we'll take the invalid nan values and false-encode them for you" :)
 
wim
8:19 PM
"I'm not sure what's really happening" is exactly the problem!
 
but is it the problem of super?
 
wim
super masks the problem in non-obvious way.
 
you would have the same problem if you had naively replaced the baseclass, no?
the MRO is basically the same either way
 
not sure what's wrong with that super().__init__() there
 
(__main__.MyQueryDict, __main__.QueryDict, __main__.MultiValueDict, collections.OrderedDict, dict, object)
 
8:22 PM
I suspect wim spent 1+ hour tracking that down, ending up at the door of super
 
so some OrderedDict method is used in place of a dict method
 
Besides, what would you do if django didn't use super? How'd you make an ordered QueryDict then?
 
Can't one put the ordered dict first or something?
 
IIRC Python2.7 ordereddict is a python implementation, so they probably made some assumptions about when overriden methods are called
 
wim
@MisterMiyagi looks good, right?
so why it doesn't work? and why it does work on 3.5?
 
8:25 PM
collections.OrderedDict is now implemented in C, which makes it 4 to 100 times faster.
 
wim
I don't care about fast. I care about not corrupting data
 
this implies that the method resolution has changed
 
Yeah I still have no clue what the problem is or how super().__init__(key_to_list_mapping) is connected to it :/
 
From the duplication I'd think that some initialization is being executed twice, but that's what super() should prevent usually...
 
8:29 PM
@Kevin @roganjosh @AndrasDeak the data i retrieve are coming from an excel file, that's why they come in and are translated to NaNs , there is no way to actually remove those NaNs?
 
duplicates are the point of the class
the problem is that strings are split to duplicates
z="33" => z="3", z="3"
 
@JoeSaad yes, there is a way. Are you using the csv module?
 
wim
it's actually a pretty fun question maybe I should ask this on main
 
Is there any way to read input when there is extra space in input formatting? For example- 2 3 4 5. split(' ') will not work here, as, the extra space character between 3 and 4 can't be converted into int
 
go ahead, I surely want to know now ^^
 
8:30 PM
@MisterMiyagi oh, I managed to consistently miss that detail ~ 4 times...
@taritgoswami what are you really trying to ask? What doesn't work?
 
@JoeSaad or pandas. But in that case, I'm not sure why you have what seem to be Python NaN values
 
@roganjosh using pandas
 
How do you want them to be handled on the front-end? What's the context? I think you've only mentioned that there's a parse error
 
@taritgoswami Any reason why you don't just use .split()?
>>> '1 2  3'.split()
['1', '2', '3']
 
Ah, either an empty string or 0
 
8:34 PM
@AndrasDeak Sometimes in online contests, there are bugs in hidden test cases, I heard that there is a way in C++ to handle that situation(I don't know how though). Is there any way to handle when there is extra space between two consecutive inputs?
 
@JoeSaad df = df.fillna(0) prior to whatever it is you do to create the JSON
 
@taritgoswami Of course there is, the reason I asked what doesn't work is that your original question contained no information. Aran has shown you since how to do that. You should default to splitting on any whitespace unless you know for a fact that you want to split on a fixed number of spaces
 
@Aran-Fey I write like, lst= list(map(int,input().split())
 
@taritgoswami don't call it arr, it's not an array. It's a list.
 
@AndrasDeak Ok fixed
 
8:37 PM
@taritgoswami that should work
 
Is it possible to create one of those Date Selection widgets in Python?
 
@AndrasDeak Ooh, actually I've used list(map(int,input().split(' ')) , I learnt that list(map(int,input().split()) and list(map(int,input().split(' ')) are same
 
@taritgoswami but they are not the same
 
What is a Data Selection widget?
 
and what libraries are we talking?
 
8:39 PM
@AndrasDeak Can you tell me what's the difference then? I knew that, by default split() splits where there is a space character
 
@taritgoswami where there is any block of whitespace characters, stripping away leading and trailing whitespace
 
Instance of 'dict' has no 'fillna' member
 
>>> ' potato     potatoe '.split()
['potato', 'potatoe']

>>> ' potato     potatoe '.split(' ')
['', 'potato', '', '', '', '', 'potatoe', '']
@JoeSaad that sounds reasonable to me
 
I was thinking tkinter possibly, and the widget that when you try to enter a date the miniature calendar appears and allows you to scrolls through the months and days.
 
@AndrasDeak Ok got it. Thanks :)
 
8:41 PM
@JoeSaad "no 'fillna' member" err. Is that the exact text of the error?
 
@roganjosh probably not but it's clear enough that they have a dict rather than a dataframe :P
I guess it's not a bad idea to extract an exact error message going forward
 
@roganjosh well, that's from the IDE. here's the one from the terminal ` 'dict' object has no attribute 'fillna'`
 
That error makes more sense. So you don't have a dataframe
Please give an MCVE because we're talking about different things here
 
guys what do u do when u r trying to install a module with pip and you get a massive traceback? Red letters saying copying this or that.
 
I start by putting all the letters back into the English language :P
 
8:45 PM
It s kinda scary
i mean its a module right in this example fitz its available to download
 
pls stop u-sing 2 much txtspk, its hard 2 c what ur tryna say
 
it has to do with my system ... Sorry
 
Try looking at the massive traceback and find the key errors. One common reason is if you're trying to install into the system python without root privileges.
 
Red letters mean it failed. It doesn't indicate that some explosive device has been activated. Read through the errors and try and find the pertinent parts. A lot of it will be code that you can't control
 
There's no shortcut to skimming the full error message.
 
8:48 PM
I will read this carefully and try to comprehend and narrow the problem down
 
wim
Asked on main for anyone who wants easy points Creating an order-preserving multi-value dict for Django
 
please don't ask for help with questions you've asked newly on main
 
Jinja2 can give some pretty big tracebacks. I just skim through for the parts that don't have Anaconda/site_packages in the file path to find the lines where I screwed up
 
@roganjosh yeah, but that takes some practice, I can understand if it's daunting at first. But one can only learn the ropes by taking the time to read the errors.
 
@roganjosh @AndrasDeak @Kevin i was able to solve the issue. I had to replace using .fillna as you guys suggested right before finding it casted to .todict() and then it works now on the frontend
 
8:51 PM
@JoeSaad there's no need to ping us all, especially with an empty message
 
All of the pings!
 
wim
@AndrasDeak sorry ;)
 
@AndrasDeak sure, I wasn't trying to dismiss it, but I assumed they wanted tips :)
 
@AndrasDeak i pressed enter by mistake before writing the message :-/
@roganjosh @Kevin @AndrasDeak i want to thank you all :)
 
no problem
 
8:54 PM
Side note: I've gone back and edited several of my comments recently to add pings because there was a lot of parallel conversations. My default position is not to ping because the 3 people you're pinging are regulars and probably watching. But I'm glad you got it sorted :)
 
Thank you
 
wim
ooh, OrderedCounter recipe was kicked out of the stdlib docs 3.6, 3.7
 
@Aran-Fey still haven't gotten around to actually solve it btw. I got far enough to understand why I'd want to have a delegate class instead of just a function that walks the mro
but hearing about silksong got me hyped about hollow knight again, so I need to replay it
poor me =/
 
Try to avoid the spoilers when you read the transcript (:
 
Still a good question imo
 
wim
8:59 PM
also TIL OrderedDict.move_to_end. How long has that been there?
 
thanks for the warning =)
 
> New in version 3.2.
unless it was rhetorical
 
super().move_to_end(key) <- why not self.move_to_end(key)?!
 
wim
also
* Until Python 3.8, dict lacked a __reversed__() method.
in the 3.7 docs (documentation from the future, marty!)
@AndrasDeak Do I know what rhetorical means!
@Aran-Fey good question
 
9:21 PM
Can anyone help me work out why its printing every URL?
from bs4 import BeautifulSoup
import requests

def get_source(url):
    return requests.get(url).content

def is_forum_link(self):
    return self.find('special string') != -1

landing = get_source("https://**********.com/forum/")
soup = BeautifulSoup(landing, 'lxml')
forums = soup.findAll('a')

print(list(filter(is_forum_link, forums)))
 
@wim I really hate directed questions, sorry, but I had hoped you'd jump on an earlier question I had about unit testing my login authorisation on Flask (hours before you signed on). Do you have 2 mins to give suggestions on how to correctly test my code if I post a link again?
 
Also tried return "special string" in self
 
I don't understand what that last comment means
 
Are you talking to me?
 
Yep :)
 
9:26 PM
I also tried that as the line for is_forum_link :)
Instead of return self.find('special string') != -1
 
There is no class in your code. Prior to print(list(filter(is_forum_link, forums))) do you get your expected output?
 
wim
@roganjosh Maybe. I didn't see it.
FWIW there are much better people to ask Flask questions than me around here.
 
I'm not it either, cbg. x)
 
@wim It's not so much about Flask but testing methodology. I have user groups and views are decorated with something like @require_group('something'). I want to check that unauthorised users get rejected but the mechanism is quite convoluted. My code is here to make the mechanism work
Thats 4 classes/functions. In reality, all 4 have to work as a unit to be successful. That makes me think I should have a test that uses all 4, but that doesn't feel like a "unit" at the same time. Should I be testing each component, or just the system as a whole?
I haven't done unit testing before and trying to teach myself, but I'm a bit lost on what I should be shooting for with that when I want to check that the decorator on a view function will just kick the user to the login page
 
9:45 PM
@roganjosh My general approach to tests is to write them in such a way that I will be notified when something in my code breaks. One thing to be careful about is that you shouldn't test functionality of libraries and frameworks.
 
So the unit would really be all 4 functions/classes working together?
(ugh I misread the pastebin format and "fixed" what I thought was an indentation issue but it was actually correct in the first place:pastebin.com/3RtTnuYV)
 
wim
pastebin blocked at WimCorp.
 
Oh :/
 
@wim does it count that I basically answered the "why does it work in 3.5" in time?
 
Well, I can ask you what would be an acceptable format or just leave it because I don't want to trouble you too much
 
wim
10:06 PM
@roganjosh gist
@MisterMiyagi does what count?
 
wim
10:43 PM
pretty good answer
did I convinced you that super is... well.. "you can't use it"??
 
11:04 PM
you can't use it to combine classes that are incompatible
 

« first day (3131 days earlier)      last day (1817 days later) »