From 3721a7151b399004b878ccc11a8ad25e981720db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 9 Mar 2025 18:21:38 +0100 Subject: [PATCH] Class, Plotly --- README.md | 19 ++++++++++--------- index.html | 23 ++++++++++++----------- parse.js | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 7a4b022..d07d6bf 100644 --- a/README.md +++ b/README.md @@ -999,7 +999,7 @@ raise Exception() print/str/repr([]) print/str/repr({: }) f'{!r}' -Z = dataclasses.make_dataclass('Z', ['a']); print/str/repr(Z()) +Z = make_dataclass('Z', ['a']); print/str/repr(Z()) >>> ``` @@ -1034,9 +1034,9 @@ class C(A, B): pass ```python from collections import abc -: [| ...] [= ] # `|` since 3.10. -: list/set/abc.Iterable/abc.Sequence[] [= ] # Since 3.9. -: dict/tuple[, ...] [= ] # Since 3.9. +: [| ...] [= ] +: list/set/abc.Iterable/abc.Sequence[] [= ] +: dict/tuple[, ...] [= ] ``` ### Dataclass @@ -1056,9 +1056,9 @@ class : * **For attributes of arbitrary type use `'typing.Any'`.** ```python -Point = make_dataclass('Point', ['x', 'y']) -Point = make_dataclass('Point', [('x', float), ('y', float)]) -Point = make_dataclass('Point', [('x', float, 0), ('y', float, 0)]) +P = make_dataclass('P', ['x', 'y']) +P = make_dataclass('P', [('x', float), ('y', float)]) +P = make_dataclass('P', [('x', float, 0), ('y', float, 0)]) ``` ### Property @@ -3440,7 +3440,7 @@ import plotly.express as px, pandas as pd ```python covid = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/8dde8ca49b' '6e648c17dd420b2726ca0779402651/public/data/owid-covid-data.csv', - usecols=['iso_code', 'date', 'total_deaths', 'population']) + usecols=['iso_code', 'date', 'population', 'total_deaths']) continents = pd.read_csv('https://gto76.github.io/python-cheatsheet/web/continents.csv', usecols=['Three_Letter_Country_Code', 'Continent_Name']) df = pd.merge(covid, continents, left_on='iso_code', right_on='Three_Letter_Country_Code') @@ -3483,7 +3483,8 @@ def get_ticker(driver, name, symbol): driver.get(url + '?period1=1579651200&period2=9999999999') if buttons := driver.find_elements('xpath', '//button[@name="reject"]'): buttons[0].click() - dataframes = pd.read_html(io.StringIO(driver.page_source), parse_dates=['Date']) + html = io.StringIO(driver.page_source) + dataframes = pd.read_html(html, parse_dates=['Date']) s = dataframes[0].set_index('Date').Open return s.rename(name) diff --git a/index.html b/index.html index b8998d7..e685859 100644 --- a/index.html +++ b/index.html @@ -56,7 +56,7 @@
- +
@@ -847,7 +847,7 @@ csv.writer(<file>).writerow([<obj>])

Expressions that call the repr() method:

print/str/repr([<obj>])
 print/str/repr({<obj>: <obj>})
 f'{<obj>!r}'
-Z = dataclasses.make_dataclass('Z', ['a']); print/str/repr(Z(<obj>))
+Z = make_dataclass('Z', ['a']); print/str/repr(Z(<obj>))
 >>> <obj>
 
@@ -875,9 +875,9 @@ Z = dataclasses.make_dataclass('Z', [Hints are used by type checkers like mypy, data validation libraries such as Pydantic and lately also by Cython compiler. However, they are not enforced by CPython interpreter.
from collections import abc
 
-<name>: <type> [| ...] [= <obj>]                              # `|` since 3.10.
-<name>: list/set/abc.Iterable/abc.Sequence[<type>] [= <obj>]  # Since 3.9.
-<name>: dict/tuple[<type>, ...] [= <obj>]                     # Since 3.9.
+<name>: <type> [| ...] [= <obj>]
+<name>: list/set/abc.Iterable/abc.Sequence[<type>] [= <obj>]
+<name>: dict/tuple[<type>, ...] [= <obj>]
 
@@ -897,9 +897,9 @@ Z = dataclasses.make_dataclass('Z', [Function field() is needed because '<attr_name>: list = []' would make a list that is shared among all instances. Its 'default_factory' argument can be any callable.
  • For attributes of arbitrary type use 'typing.Any'.
  • -
    Point = make_dataclass('Point', ['x', 'y'])
    -Point = make_dataclass('Point', [('x', float), ('y', float)])
    -Point = make_dataclass('Point', [('x', float, 0), ('y', float, 0)])
    +
    P = make_dataclass('P', ['x', 'y'])
    +P = make_dataclass('P', [('x', float), ('y', float)])
    +P = make_dataclass('P', [('x', float, 0), ('y', float, 0)])
     

    Property

    Pythonic way of implementing getters and setters.

    class Person:
         @property
    @@ -2803,7 +2803,7 @@ z
     

    Displays a line chart of total coronavirus deaths per million grouped by continent:

    covid = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/8dde8ca49b'
                         '6e648c17dd420b2726ca0779402651/public/data/owid-covid-data.csv',
    -                    usecols=['iso_code', 'date', 'total_deaths', 'population'])
    +                    usecols=['iso_code', 'date', 'population', 'total_deaths'])
     continents = pd.read_csv('https://gto76.github.io/python-cheatsheet/web/continents.csv',
                              usecols=['Three_Letter_Country_Code', 'Continent_Name'])
     df = pd.merge(covid, continents, left_on='iso_code', right_on='Three_Letter_Country_Code')
    @@ -2842,7 +2842,8 @@ px.line(df, x='Date', y='?period1=1579651200&period2=9999999999')
         if buttons := driver.find_elements('xpath', '//button[@name="reject"]'):
             buttons[0].click()
    -    dataframes = pd.read_html(io.StringIO(driver.page_source), parse_dates=['Date'])
    +    html = io.StringIO(driver.page_source)
    +    dataframes = pd.read_html(html, parse_dates=['Date'])
         s = dataframes[0].set_index('Date').Open
         return s.rename(name)
     
    @@ -2943,7 +2944,7 @@ $ deactivate                # Deactivates the active
      
     
       
     
    diff --git a/parse.js b/parse.js
    index 1c660ed..51a02ab 100755
    --- a/parse.js
    +++ b/parse.js
    @@ -76,7 +76,7 @@ const REPR_USE_CASES =
       'print/str/repr([<obj>])\n' +
       'print/str/repr({<obj>: <obj>})\n' +
       'f\'{<obj>!r}\'\n' +
    -  'Z = dataclasses.make_dataclass(\'Z\', [\'a\']); print/str/repr(Z(<obj>))\n' +
    +  'Z = make_dataclass(\'Z\', [\'a\']); print/str/repr(Z(<obj>))\n' +
       '>>> <obj>\n';
     
     const CONSTRUCTOR_OVERLOADING =