Meta tags:
Headings (most frequently used words):
2022, python, june, friendly, october, final, thoughts, tuesday, friday, with, only, thursday, 27, 18, monday, september, 19, 17, 14, saturday, 11, using, ideas, may, 13, blog, archive, about, me, better, nameerror, messages, for, pandas, settingwithcopywarning, did, get, it, right, new, milestone, traceback, version, and, why, not, friendly_idle, is, done, idle, nicer, arithmetic, fun, emojis,
Text of the page (most frequently used words):
the (119), this (48), python (46), that (38), with (35), for (34), #friendly (32), and (30), you (26), can (25), not (24), from (22), dataframe (22), share (21), use (21), copy (19), ideas (18), series (18), import (17), traceback (17), pandas (16), code (16), have (15), loc (15), about (14), using (14), some (14), indexing (14), example (13), had (13), what (13), december (12), see (12), done (12), fraction (12), january (11), june (11), original (11), which (11), used (10), march (10), instead (10), however (10), result (10), version (10), something (10), november (9), april (9), settingwithcopywarning (9), better (9), when (9), also (9), but (9), one (9), was (9), does (9), support (9), line (9), like (9), has (9), first (9), friendly_idle (9), value (9), new (8), andré (8), roberge (8), february (8), october (8), 2022 (8), module (8), out (8), same (8), created (8), more (8), point (8), are (8), arithmetic (8), your (8), chained (8), try (7), may (7), pinterest (7), facebook (7), blogthis (7), email (7), comments (7), posted (7), file (7), would (7), made (7), floating (7), number (7), will (7), following (7), decimal (7), idle (7), only (7), been (7), view (6), just (6), august (6), september (6), did (6), nameerror (6), emojis (6), 30000000000000004 (6), syntax (6), second (6), set (6), why (6), https (6), indirect (6), df2 (6), series_1 (6), july (5), get (5), blog (5), all (5), much (5), modules (5), such (5), fractions (5), here (5), found (5), note (5), data (5), org (5), contained (5), could (4), console (4), modify (4), cpython (4), project (4), included (4), way (4), run (4), cannot (4), above (4), examples (4), hooks (4), modified (4), help (4), mentioned (4), before (4), simple_math (4), different (4), rational (4), already (4), own (4), often (4), there (4), case (4), name (4), then (4), suspect (4), likely (4), next (4), warning (4), where (4), trying (4), slice (4), caveats (4), documentation (4), pydata (4), docs (4), stable (4), user_guide (4), html (4), returning (4), versus (4), information (4), potential (4), suggestion (4), missing (4), pamela (4), programming (3), things (3), messages (3), posts (3), need (3), jupyter (3), notebooks (3), pythonji (3), tweet (3), terminal (3), including (3), suggested (3), notation (3), how (3), achieve (3), ipython (3), rational_math (3), print (3), thus (3), package (3), while (3), results (3), limit_denominator (3), recent (3), operations (3), values (3), 3000000 (3), particular (3), many (3), since (3), provide (3), sys (3), announcement (3), errors (3), defined (3), highlighting (3), course (3), post (3), say (3), always (3), quite (3), added (3), install (3), considered (3), indexed (3), effect (3), goal (3), block (3), issued (3), direct (3), mean (3), typo (3), fox (3), third (3), party (3), either (2), create (2), learn (2), started (2), time (2), languages (2), 2018 (2), right (2), works (2), source (2), any (2), too (2), attempt (2), geir (2), arne (2), hjelle (2), fun (2), implement (2), available (2), imported (2), possible (2), even (2), they (2), programmers (2), friday (2), nicer_float (2), regular (2), inaccuracy (2), given (2), think (2), nice (2), easy (2), very (2), interactive (2), final (2), thoughts (2), enhanced (2), type (2), hook (2), let (2), starting (2), shown (2), perform (2), know (2), its (2), named (2), raymond (2), hettinger (2), fact (2), converting (2), similar (2), standard (2), provides (2), look (2), getcontext (2), fixed (2), limited (2), common (2), explaining (2), followed (2), beginning (2), write (2), backported (2), raised (2), because (2), user (2), monospace (2), font (2), friendly_traceback (2), might (2), doing (2), contains (2), error (2), than (2), partial (2), now (2), really (2), tuesday (2), decided (2), feedback (2), previous (2), latest (2), improved (2), previously (2), end (2), both (2), these (2), being (2), cases (2), makes (2), few (2), show (2), tracebacks (2), problem (2), order (2), two (2), possibilities (2), tried (2), chaining (2), assign (2), index_2 (2), index_1 (2), list (2), appears (2), suggest (2), importlib (2), util (2), find_spec (2), installed (2), near (2), yet (2), potentially (2), stdlib_module_names (2), initially (2), improvements (2), names (2), stream (2), stringio (2), most (2), call (2), last (2), stdin (2), theme, images, powered, blogger, gaffera, complete, profile, preferably, hobby, completely, useless, explore, features, software, others, recently, learning, journey, human, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020, 2021, archive, subscribe, atom, home, older, importing, work, running, leaving, extension, without, learned, thought, little, below, basic, mike, driscoll, undeterred, called, pypi, enabled, restricted, ending, nor, year, prior, allowed, environments, repl, unsurprisingly, rejected, pull, request, thomas, caswell, perhaps, prefer, numpy, euroscipy, pointing, scientific, alias, everything, marc, garcia, gave, lightning, talk, adopted, pyret, immediately, preceded, treated, approximate, points, confusing, beginners, built, switch, modes, calculations, doubt, ever, happen, fortunately, demonstrated, 0b1, add_hook, initializing, brief, executing, script, nicer_floats, alternatively, execute, getting, expected, unintuitive, instruct, suppose, containing, readers, facilitate, creation, enable, experimentation, comes, intuitive, special, simple, says, 1_000_000_000, restrictive, limitation, imposed, denominator, float, means, carries, intrinsic, determine, places, into, achieved, method, class, parsing, 3602879701896397, 36028797018963968, yield, surprising, string, arguments, represent, floats, mcgugan, rich, textual, fame, another, alternative, library, precision, decimals, performed, printed, carry, extra, zeros, prec, alternatives, exists, site, inspired, devoted, origin, puzzling, com, surprised, inaccuracies, saying, broken, follows, nicer, saturday, excepthook, actually, pointed, exceptions, captured, exception, fear, perfectly, capable, unfortunately, tkinter, errorbox, assumed, formatting, allow, customization, figure, dialog, hopefully, colour, anyone, experience, feel, free, contact, helpful, true, well, runtime, launch, clue, window, title, quick, eventually, plan, longer, patch, seamless, friend, incorporated, within, released, changed, wait, until, users, fix, annoyance, twitter, solution, remaining, issue, highlighted, codes, removed, design, focus, attention, area, problems, don, yourself, appreciated, bit, tamil, russian, supported, language, location, described, builds, want, interested, retrieving, produced, format, websites, making, successfully, mature, enough, other, covered, interesting, additions, planned, postpone, giving, futurecoder, www, hackinscience, hours, bumped, minor, keep, them, sync, minutes, ago, isidentical, reply, able, tweeted, pypy, implemented, going, part, milestone, monday, dataframes, causing, multiples, frames, content, specific, occasionally, emits, directly, indirectly, during, extraction, types, automatically, assigment, caused, emit, essentially, amount, except, extract, xyz, columns, index, looking, automated, read, confuse, people, correct, suggestions, typos, builtin, who, never, dotted, attribute, message, include, additional, hint, adds, make, allows, suggesting, friendly_pandas, future, unlike, single, those, excited, pep, 657, fine, grained, locations, please, dedicated, demonstrate, addition, family, tested, far, find, relevant, uses, check, located, output, chosen, explain, windows, exist, revise, room, couple, screenshots, behaviour, stage, pun, intended, competition, surprise, came, were, popular, libraries, scope, pablo, galindo, salgado, aka, provided, forget, useful, consider, having, discussion, barely, alpha, release, thursday, deals, almost, exclusively, coding, activities,
Text of the page (random words):
rectly and you then attempt to assign a value to the result by direct chained indexing we mean that your code contains something like index_1 index_2 during the first extraction using index_1 pandas found that the series to be created contained values of different types it automatically created a new series converting all values to a common type the second indexing index_2 was then done a this copy instead of the original dataframe thus the assigment was not done on the original dataframe which caused pandas to emit this warning an indirect chained indexing essentially amount to the same problem except that the second indexing is not done on the same line as that which was done to extract the first series in 5 can i get more specific information for what i just did why you used direct chained indexing of a dataframe which made a copy of the original content of the dataframe if you try to assign a value to that copy the original dataframe will not be modified instead of doing a direct chained indexing df loc b x try df loc b x in 6 what about if i tried to use indirect chaining there are two possibilities series df loc b series x 99 settingwithcopywarning a value is trying to be set on a copy of a slice from a dataframe see the caveats in the documentation https pandas pydata org pandas docs stable user_guide indexing html returning a view versus a copy in 7 where warning issued on line 4 of code block 6 1 what about if i tried to use indirect chaining 2 there are two possibilities 3 series df loc b 4 series x 99 in 8 why i suspect that you used indirect chained indexing of a dataframe first you likely created a series using something like series df loc this made a copy of the data contained in the dataframe next you indexed that copy series x this had no effect on the original dataframe if your goal is to modify the value of the original dataframe try something like the following instead df loc x in 9 what if i do things in a different order series_1 df x series_1 loc b 99 settingwithcopywarning a value is trying to be set on a copy of a slice from a dataframe see the caveats in the documentation https pandas pydata org pandas docs stable user_guide indexing html returning a view versus a copy in 10 where warning issued on line 3 of code block 9 1 what if i do things in a different order 2 series_1 df x 3 series_1 loc b 99 in 11 why i suspect that you used indirect chained indexing of a dataframe first you likely created a series using something like series_1 df this made a copy of the data contained in the dataframe next you indexed that copy series_1 loc b this had no effect on the original dataframe if your goal is to modify the value of the original dataframe try something like the following instead df loc b in 12 what if i had multiples data frames df2 df copy series df loc b series x 99 settingwithcopywarning a value is trying to be set on a copy of a slice from a dataframe see the caveats in the documentation https pandas pydata org pandas docs stable user_guide indexing html returning a view versus a copy in 13 where warning issued on line 4 of code block 12 2 df2 df copy 3 series df loc b 4 series x 99 in 14 why in your code you have the following dataframes df2 df i do not know which one is causing the problem here i will use the name df2 as an example i suspect that you used indirect chained indexing of a dataframe first you likely created a series using something like series df2 loc this made a copy of the data contained in the dataframe next you indexed that copy series x this had no effect on the original dataframe if your goal is to modify the value of the original dataframe try something like the following instead df2 loc x posted by andré roberge at 4 07 pm no comments email this blogthis share to x share to facebook share to pinterest monday september 19 2022 new milestone friendly friendly traceback version 0 6 and why not 1 0 just a few minutes ago isidentical tweeted that pypy 3 9 had implemented the new enhanced tracebacks that are going to be part of cpython 3 11 of course i had to reply to show that friendly friendly traceback have been able to do the same with all cpython version starting with 3 6 1 a few hours before this tweet i had bumped the minor version number of both friendly and friendly traceback from 0 5 to 0 6 i always keep them in sync previously friendly traceback was at 0 5 63 and friendly was at 0 5 42 friendly builds on friendly traceback and is the package you want to install as an end user if you re just interested at retrieving the data produced by friendly traceback and format it your own way as do https www hackinscience org and https futurecoder io then you only need to install friendly traceback both these websites have been making use of friendly traceback quite successfully for quite a while from that point of view friendly traceback is really mature enough to be considered as being a 1 0 version however other than always including more cases being covered i have some interesting new additions planned which makes me postpone giving it a 1 0 version number quite a bit has been done since version 0 5 in particular tamil and russian have been added as supported language the syntax highlighting of the traceback location has been improved in friendly support for a new project friendly_idle has been added i ve previously described note that when some new highlighted code is shown with friendly_idle the highlighting done on previous line of codes is removed this is by design to help focus the attention on the latest area with problems i could say more about friendly but why don t you try it out by yourself and see what you think feedback is always appreciated posted by andré roberge at 1 42 pm no comments email this blogthis share to x share to facebook share to pinterest friday june 17 2022 friendly_idle is done friendly_idle is done i ve found a better solution for the remaining issue i had mentioned in the previous blog post i also found a fix for an annoyance mentioned by raymond hettinger on twitter i could have changed the version to 1 0 but decided to wait until i get more feedback from users posted by andré roberge at 4 28 pm no comments email this blogthis share to x share to facebook share to pinterest tuesday june 14 2022 friendly idle friendly_idle is now available this is just a quick announcement eventually i plan to write a longer blog post explaining how i use import hooks to patch idle and to provide seamless support for friend friendly_traceback before i incorporated partial support for idle within friendly i had released a package named friendly_idle but this is really a much better version when you launch it from a terminal the only clue you get that this is not your regular idle is from the window title since python 3 10 and backported to python 3 8 10 and 3 9 5 idle provide support for sys excepthook see announcement actually in the announcement it is not pointed out that this is only partial support exceptions raised because of syntax errors cannot be captured by user defined exception hooks however fear not friendly_idle is perfectly capable to help you when your code has some syntax errors and of course it can also do so for runtime errors the same is true for code run from a file as well if the code in a file contains some syntax error friendly_idle is often much more helpful than idle here s an example from idle and the same example run using friendly_idle unfortunately the tkinter errorbox does not use a monospace font assumed by friendly friendly_traceback for the formatting and does not allow customization i might have to figure out how to create my own dialog hopefully with support for monospace font and colour highlighting if anyone has some experience doing this feel free to contact me posted by andré roberge at 8 10 am no comments email this blogthis share to x share to facebook share to pinterest saturday june 11 2022 nicer arithmetic with python beginning programmers are often surprised by floating point arithmetic inaccuracies if they use python many will often write posts saying that python is broken when the see results as follows 0 1 0 2 0 30000000000000004 this particular result is not limited to python in fact it is so common that there exists a site with a name inspired by this example 0 30000000000000004 com devoted to explaining the origin of this puzzling result followed by examples from many programming languages python provides some alternatives to standard floating point operations for example one can use the decimal module to perform fixed point arithmetic operations here s an example from decimal import decimal getcontext getcontext prec 7 decimal 0 1 decimal 0 2 decimal 0 3000000 print _ 0 3000000 while one can set the precision number of decimals with which operations are performed printed values can carry extra zeros 0 3000000 does not look as nice as 0 3 another alternative included with python s standard library is the fractions module it provides support for rational number arithmetic from fractions import fraction fraction 0 1 fraction 0 2 fraction 3 10 print _ 3 10 however the fractions module can yield some surprising results if one does not use string arguments to represent floats as was mentioned by will mcgugan of rich and textual fame in a recent tweet from fractions import fraction as f f 0 1 fraction 1 10 f 0 1 fraction 3602879701896397 36028797018963968 in the second case 0 1 is a float which means that it carries some intrinsic inaccuracy for the first case some parsing is done by python to determine the number of decimal places to use before converting the result into a rational number a similar result can be achieved using the limit_denominator method of the fraction class f 0 1 limit_denominator 10 fraction 1 10 in fact we do not have to be as restrictive in the limitation imposed on the denominator to achieve the same result f 0 1 limit_denominator 1_000_000_000 fraction 1 10 while we can achieve some more intuitive results for floating point arithmetic using special modules from python the notation that one has to use is not as simple as 0 1 0 2 as raymond hettinger often says there has to be a better way using ideas as readers of this blog already know i created a python package named ideas to facilitate the creation of import hooks and to enable easy experimentation with modified python syntax ideas comes with its own console that support modified python syntax it can also be used with ipython and thus with jupyter notebooks using ideas one can instruct python to perform rational arithmetic for example suppose i have a python file containing the following simple_math py a 0 2 0 1 b 0 2 1 10 c 2 10 1 10 print a b c i can run this with python getting the expected unintuitive result py simple_math py 0 30000000000000004 0 30000000000000004 0 30000000000000004 alternatively using ideas i can execute this file using rational arithmetic ideas simple_math a rational_math 3 10 3 10 3 10 using a different import hook i can have the result shown with floating point notation ideas simple_math a nicer_floats 0 3 0 3 0 3 instead of executing a script let s use the ideas console instead starting with nicer_float ideas 0 1 0 2 0 3 ideas 1 10 2 10 0 3 for nicer_float i ve also adopted the pyret s notation floating point number immediately preceded by are treated as approximate floating points i e with the regular inaccuracy ideas 0 1 0 2 0 30000000000000004 and as mentioned before i can use ideas with ipython here s a very brief example ipython 8 0 0b1 an enhanced interactive python type for help in 1 from ideas examples import rational_math in 2 hook rational_math add_hook the following initializing code from ideas is included from fractions import fraction in 3 0 1 0 2 out 3 fraction 3 10 final thoughts given how confusing floating point arithmetic is to beginners i think it would be nice if python had an easy built in way to switch modes and do calculations as done with ideas in the above examples however i doubt very much that this will ever happen fortunately as demonstrated above it is possible to use import hooks and modified interactive console to achieve this result posted by andré roberge at 8 20 am no comments email this blogthis share to x share to facebook share to pinterest friday may 13 2022 python fun with emojis at euroscipy in 2018 marc garcia gave a lightning talk which started by pointing out that scientific python programmers like to alias everything such as import numpy as np import pandas as pd and suggested that they perhaps would prefer to use emojis such as import pandas as however python does not support emojis as code so the above line cannot be used a year prior thomas a caswell had created a pull request for cpython that would have made this possible this code would have allowed the use of emojis in all environments including in a python repl and even in jupyter notebooks unsurprisingly this was rejected undeterred geir arne hjelle created a project called pythonji available on pypi which enabled the use of emojis in python code but in a much more restricted way with pythonji one can run modules ending with instead of py from a terminal however such modules cannot be imported nor can emojis be used in a terminal when i learned about this attempt by geir arne hjelle from a tweet by mike driscoll i thought it would be a fun little project to implement with ideas below i use the same basic example included in the original pythonji project as you can see it works in ideas console when importing module it can also work when running the file as source but leaving the extension out and it works in jupyter notebooks too all of this without any need to modify cpython s source code posted by andré roberge at 7 40 pm no comments email this blogthis share to x share to facebook share to pinterest older posts home subscribe to posts atom blog archive 2022 11 october 2 better nameerror messages for python pandas settingwithcopywarning did i get it right september 1 june 3 may 1 april 1 february 2 january 1 2021 21 december 1 november 1 october 1 july 4 march 3 february 4 january 7 2020 15 december 5 october 1 august 4 july 1 march 2 february 2 2019 12 december 6 june 1 may 4 april 1 2018 4 november 1 june 3 2017 8 november 1 september 1 august 2 may 2 april 2 2016 5 december 1 september 2 march 1 january 1 2015 18 december 7 october 3 june 2 april 1 january 5 2014 24 december 4 november 10 june 1 may 4 april 3 march 1 february 1 2013 2 march 1 february 1 2012 1 march 1 2011 3 december 1 september 1 january 1 2010 7 august 1 january 6 2009 11 december 2 november 1 september 3 august 2 april 2 january 1 2008 36 december 8 november 2 october 9 june 1 april 3 march 3 february 3 january 7 2007 29 december 8 november 3 october 1 august 4 july 3 june 2 march 1 february 3 january 4 2006 45 november 3 august 2 july 1 june 4 may 9 april 5 march 1 february 10 january 10 2005 17 december 2 july 1 may 4 apri...
|