What’s new¶
All notable changes to this project will be documented in this file.
By import convention, components of the Sciris library are listed beginning with sc.
, e.g. sc.odict()
.
Version 1.1.1 (2021-03-17)¶
The implementations of
sc.odict()
andsc.objdict()
have been updated, to allow for more flexible use of thedefaultdict
argument, including better nesting and subclassing.A new
serial
argument has been added tosc.parallelize()
to allow for quick debugging.Legacy support for Python 2 has been removed from
sc.loadobj()
andsc.saveobj()
.A fallback method for
sc.gitinfo()
(based ongitpython
) has been added, in case reading from the filesystem fails.
Version 1.1.0 (2021-03-12)¶
New functions¶
sc.mergelists()
is similar tosc.mergedicts()
: it will take a sequence of inputs and attempt to merge them into a list.sc.transposelist()
will perform a transposition on a list of lists: for example, a list of 10 lists (or tuples) each of length 3 will be transformed into a list of 3 lists each of length 10.sc.strjoin()
andsc.newlinejoin()
are shortcuts to', '.join(items)
and'\n'.join(items)
, respectively. The latter is especially useful inside f-strings since you cannot use the\n
character.
Bugfixes¶
sc.day()
now returns a numeric array when an array of datetime objects is passed to it; a bug which was introduced in version 1.0.2 which meant it returned an object array instead.Slices with numeric start and stop indices have been fixed for
sc.odict()
.sc.objatt()
now correctly handles objects with slots instead of a dict.
Improvements¶
sc.loadobj()
now accepts aremapping
argument, which lets the user load old pickle files even if the modules no longer exist.Most file functions (e.g.
sc.makefilepath
,sc.getfilelist()
now accept anaspath
argument, which, ifTrue
, will return apathlib.Path
object instead of a string.Most array-returning functions, such as
sc.promotetoarray()
andsc.cat()
, now accept acopy
argument and other keywords; these keywords are passed tonp.array()
, allowing e.g. thedtype
to be set.A fallback option for
sc.findinds()
has been implemented, allowing it to work even if the input array isn’t numeric.sc.odict()
now has adefaultdict
argument, which lets you use it like a defaultdict as well as an ordered dict.sc.odict()
has atranspose
argument for methods likeitems()
andenumvalues()
, which will return a tuple of lists instead of a list of tuples.sc.objdict()
now prints out differently, to distinguish it from ansc.odict
.sc.promotetolist()
has a newcoerce
argument, which will convert that data type into a list (instead of wrapping it).
Renamed/removed functions¶
The functions
sc.tolist()
andsc.toarray()
have been added as aliases ofsc.promotetolist()
andsc.promotetoarray()
, respectively. You may use whichever you prefer.The
skipnone
keyword has been removed fromsc.promotetoarray()
and replaced withkeepnone
(which does something slightly different).
Other updates¶
Exceptions have been made more specific (e.g.
TypeError
instead ofException
).Test code coverage has been increased significantly (from 63% to 84%).
Version 1.0.2 (2021-03-10)¶
Fixed bug (introduced in version 1.0.1) with
sc.readdate()
returning only the first element of a list of a dates.Fixed bug (introduced in version 1.0.1) with
sc.date()
treating an integer as a timestamp rather than an integer number of days when a start day is supplied.Updated
sc.readdate()
,sc.date()
, andsc.day()
to always return consistent output types (e.g. if an array is supplied as an input, an array is supplied as an output).
Version 1.0.1 (2021-03-01)¶
Fixed bug with Matplotlib 3.4.0 also defining colormap
'turbo'
, which caused Sciris to fail to load.Added a new function,
sc.orderlegend()
, that lets you specify the order you want the legend items to appear.Fixed bug with paths returned by
sc.getfilelist(nopath=True)
.Fixed bug with
sc.loadjson()
only reading from a string iffromfile=False
.Fixed recursion issue with printing
sc.Failed
objects.Changed
sc.approx()
to be an alias tonp.isclose()
; this function may be removed in future versions.Changed
sc.findinds()
to callnp.isclose()
, allowing for greater flexibility.Changed the
repr
forsc.objdict()
to differ fromsc.odict()
.Improved
sc.maximize()
to work on more platforms (but still not inline or on Macs).Improved the flexiblity of
sc.htmlify()
to handle tabs and other kinds of newlines.Added additional checks to
sc.prepr()
to avoid failing on recursive objects.Updated
sc.mergedicts()
to return the same type as the first dict supplied.Updated
sc.readdate()
andsc.date()
to support timestamps as well as strings.Updated
sc.gitinfo()
to try each piece independently, so if it fails on one (e.g., extracting the date) it will still return the other pieces (e.g., the hash).Pinned
xlrd
to 1.2.0 since later versions fail to read xlsx files.
Version 1.0.0 (2020-11-30)¶
This major update (and official release!) includes many new utilities adopted from the Covasim and Atomica libraries, as well as important improvements and bugfixes for parallel processing, object representation, and file I/O.
New functions¶
Math functions¶
sc.findfirst()
andsc.findlast()
return the first and last indices, respectively, of whatsc.findinds()
would return. These keywords (first
andlast
) can also be passed directly tosc.findinds()
.sc.randround()
probabilistically rounds numbers to the nearest integer; e.g. 1.2 will round down 80% of the time.sc.cat()
is a generalization ofnp.append()
/np.concatenate()
that handles arbitrary types and numbers of inputs.sc.isarray()
checks if the object is a Numpy array.
Plotting functions¶
A new diverging colormap,
'orangeblue'
, has been added (courtesy Prashanth Selvaraj). It is rather pretty; you should try it out.sc.get_rows_cols()
solves the small but annoying issue of trying to figure out how many rows and columns you need to plot N axes. It is similar tonp.unravel_index()
, but allows the desired aspect ratio to be varied.sc.maximize()
maximizes the current figure window.
Date functions¶
sc.date()
will convert practically anything to a date.sc.day()
will convert practically anything to an integer number of days from a starting point; for example,sc.day(sc.now())
returns the number of days since Jan. 1st.sc.daydiff()
computes the number of days between two or more start and end dates.sc.daterange()
returns a list of date strings or date objects between the start and end dates.sc.datetoyear()
converts a date to a decimal year (from Romesh Abeysuriya via Atomica).
Other functions¶
The “flagship” functions
sc.loadobj()
/sc.saveobj()
now have shorter aliases:sc.load()
/sc.save()
. These functions can be used interchangeably.A convenience function,
sc.toctic()
, has been added that doessc.toc(); sc.tic()
, i.e. for sequentially timing multiple blocks of code.sc.checkram()
reports the current process’ RAM usage at the current moment in time; useful for debugging memory leaks.sc.getcaller()
returns the name and line number of the calling function; useful for logging and version control purposes.sc.nestedloop()
iterates over lists in the specified order (from Romesh Abeysuriya via Atomica).sc.parallel_progress()
runs a function in parallel whilst displaying a single progress bar across all processes (from Romesh Abeysuriya via Atomica).An experimental function,
sc.asobj()
, has been added that lets any dictionary-like object be used with attributes instead (i.e.foo.bar
instead offoo['bar']
).
Bugfixes and other improvements¶
sc.parallelize()
now uses themultiprocess
library instead ofmultiprocessing
. This update fixes bugs with trying to run parallel processing in certain environments (e.g., in Jupyter notebooks). This function also returns a more helpful error message when running in the wrong context on Windows.sc.prepr()
has been updated to use a simpler method of parsing objects for display; this should be faster and more robust. A default 3 second time limit has also been added.sc.savejson()
now uses an indent of 2 by default, leading to much more human-readable JSON files.sc.gitinfo()
has been updated to use the code from Atomica’sfast_gitinfo()
instead (courtesy Romesh Abeysuriya).sc.thisdir()
now no longer requires the__file__
argument to be supplied to get the current folder.sc.readdate()
can now handle a list of dates.sc.getfilelist()
now has more options, such as to return the absolute path or no path, as well as handling file matching patterns more flexibly.sc.Failed
andsc.Empty
, which may be encountered when loading a corrupted pickle file, are now exposed to the user (before they could only be accessed viasc.sc_fileio.Failed
).sc.perturb()
can now use either uniform or normal perturbations via thenormal
argument.
Renamed/removed functions¶
The function
sc.quantile()
has been removed. Please usenp.quantile()
instead (though admittedly, it is extremely unlikely you were using it to begin with).The function
sc.scaleratio()
has been renamedsc.normsum()
, since it normalizes an array by the sum.
Other updates¶
Module imports were moved to inside functions, improving Sciris loading time by roughly 30%.
All tests were refactored to be in consistent format, increasing test coverage by roughly 50%.
Continuous integration testing was updated to use GitHub Actions instead of Travis/Tox.
Version 0.17.4 (2020-08-11)¶
sc.profile()
andsc.mprofile()
now return the line profiler instance for later use (e.g., to extract additional statistics).sc.prepr()
(also used insc.prettyobj()
) can now support objects with slots instead of dicts.
Version 0.17.3 (2020-07-21)¶
sc.parallelize()
now explicitly deep-copies objects, since on some platforms this copying does not take place as part of the parallelization process.
Version 0.17.2 (2020-07-13)¶
sc.search()
is a new function to find nested attributes/keys within objects or dictionaries.
Version 0.17.1 (2020-07-07)¶
sc.Blobject
has been modified to allow more flexibility with saving (e.g.,Path
objects).
Version 0.17.0 (2020-04-27)¶
sc.mprofile()
has been added, which does memory profiling just likesc.profile()
.sc.progressbar()
has been added, which prints a progress bar.sc.jsonpickle()
andsc.jsonunpickle()
have been added, wrapping the module of the same name, to convert arbitrary objects to JSON.sc.jsonify()
checks objects for ato_json()
method, handling e.g Pandas dataframes, and falls back tosc.jsonpickle()
instead of raising an exception for unknown object types.sc.suggest()
now usesjellyfish
instead ofpython-levenshtein
for fuzzy string matching.sc.saveobj()
now uses protocol 4 instead of the latest by default, to avoid backwards incompatibility issues caused by using protocol 5 (only compatible with Python 3.8).sc.odict()
and related classes now raisesc.KeyNotFoundError
exceptions. These are derived fromKeyError
, but fix a bug in the string representation to allow multi-line error messages.Rewrote all tests to be pytest-compatible.
Version 0.16.8 (2020-04-11)¶
sc.makefilepath()
now has acheckexists
flag, which will optionally raise an exception if the file does (or doesn’t) exist.sc.sanitizejson()
now handlesdatetime.date
anddatetime.time
.sc.uuid()
andsc.fast_uuid()
now work with non-integer inputs, e.g.,sc.uuid(n=10e3)
.sc.thisdir()
now accepts additional arguments, so can be used to form a full path, e.g.sc.thisdir(__file__, 'myfile.txt')
.sc.checkmem()
has better parsing of objects.sc.prepr()
now lists properties of objects, and has some aesthetic improvements.