Skip to main content

Convenient functions and classes I use too often.

Project description

My Favorite Things

Convenient functions and classes I use too often. If Coltrane was a programmer (shudder) and much worse.

Installation

Install with

pip install my-favorite-things

Current Methods (by file)

save

save(name, savedir="", savepath="", stype="npz", absolute=False, parents=0, overwrite=False, append=False, dryrun=False, save_kwargs={}, **kwargs)

This method is used for saving data to a file. You can save as an .npz/.npy file for numpy array(s) or as a .pkl file for dictionaries and other odd python objects. By default, it will not overwrite existing files but instead append a number onto the end of file name (the keywords being, by default, overwite=False and append=True). You can save relative to your current directory (absolute=False) or as an absolute path (absolute=True). Addtionally, double check that you're saving to the correct directory with dryrun=True. Check the doc string for more info.


ddicts

nested_ddict(depth, endtype)

This method allows for creating a nested defaultdictionary. This is useful if you have data that is dependent on multiple parameters that are heirarchical. For example, if we do

d = nested_ddict(3, list)

then we can use it as

d['zero']['one']['two']['three'].append(datum)

format_ddict(ddict, make_nparr=True, sort_lists=False)

This method will format your (nested) defaultdictionary into dictionaries. Additionally, it can turns lists in numpy arrays and/or sort the lists too.

pprint_nested_dict(d, tab=2, k_format="", v_format="", sort=True, indentation=0)

Similar to Python's pprint, this will print out a dictionary such that each successive nested layer is more indented. It also has a means to format the final keys and values either with a method that they are passed to or an f-string.


plots

cumulative_bins(*arrs, num_bins)

This is similar to the previous method but for a linear scale. When plotting multiple data sets on the same plot, they may have different ranges and, thus, bin sizes. So this method will create the bin values so that the bars of the histogram will all have the same width.

log_bins(*arrs, num_bins)

This method is used for binning for histograms logarithmically. In plt.hist, setting the keyword bins to the output of this function (where arrs are the arrays being plotted) and ax.set_xscale("log") will give equally spaced bins (for multiple data sets over the logarithmic x-axis).

bar_count(ax, counts, labels, label_bars, sort_type, *, bar_params, **kwargs)

This method will create a bar plot for the data passed using strings as labels (either as the keys of a dictionary passed for counts or as a list passed from labels) with various conveniences like specifying the format of the label strings or the order of the plotted data.

histbar(ax, xs, ys, label_type=None, capends=None, fill=False, **kwargs)

Creates a step plot at the between the values in xs for the values in ys. So the former has $n+1$ values if the latter has $n$ values. Can fill in the plot via Matplotlib's fill_between using the boolean keyword fill and label the specific values of xs if they aren't uniform using label_type.

ScientificLocator(step=0.1)

This is a Locator class that will equally space ticks as step$\cdot 10^p$ where $p$ is the order of magnitude of the axis. That is, this is like MultipleLocator modulo the order of magnitude.

ScientificFormatter(useMathText=True)

An accompanying Formatter class to ScientificLocator. This class will force the axis to be in scientific notation.


colors

fader(color1, color2, fraction)

This method will return a color in hex code as a fraction between the two given colors color1 and color2.

multifader(colors, fractions)

Like above, but intermediate colors can also be defined in the colors list. These colors are equally spaced.


style

format_plots()

Changes the default values for Matplotlib plots.

format_numpy(precision=6, linewidth=1000, sign=" ")

Changes the default print options for Numpy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

my_favorite_things-0.5.1.tar.gz (51.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

my_favorite_things-0.5.1-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file my_favorite_things-0.5.1.tar.gz.

File metadata

  • Download URL: my_favorite_things-0.5.1.tar.gz
  • Upload date:
  • Size: 51.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for my_favorite_things-0.5.1.tar.gz
Algorithm Hash digest
SHA256 8c02e28eda0fbc47b5fa300004e60876221b74fe1e6eb5615722e93b3ddbb612
MD5 6e74096ff382d3e9840097b67dc06fb3
BLAKE2b-256 eb42e3aad4d44d40b2f3e851283f837d454670649cc2eb787dd0659b3366d9f8

See more details on using hashes here.

File details

Details for the file my_favorite_things-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for my_favorite_things-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 608df26e1443481115437bf623da12dbc8fb387e22f1fb6e50e3be9234fe4b8d
MD5 f8521d2d5950de547c460732bbe7d370
BLAKE2b-256 5d67bae0ab84bdf955c4ec0ba8858a0c9773d9d6a5ce77e292d848da7f5b1cee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page