Littletable

Latest version: v3.0.1

Safety actively analyzes 682487 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 8

3.0.1

-------------
- Fixed bug when using `None` as a key into a unique index.

- Fixed output width when calling `Table.present()`. Previously, this would limit the
width of the output to the current console default width (often set to 80), even if
sending the output to a file. The width can now be overridden by passing an integer
`width` argument to `Table.present()`.

- Updated `how_to_use_littletable.md` with notes on adding a `User-Agent` header when
importing data from HTTP/HTTPS urls.

3.0.0

-------------
- Removed deprecated features:
- `DataObject` class removed, replace with `typing.SimpleNamespace`, `dict`, `typing.NamedTuple`,
`collections.namedtuple`, or other user-defined class
- `Table.re_match(patt)` comparator removed, replace with `re.compile(patt).match`

- Added `median` to statistics returned from `Table.stats()`.

- Added changes to SSL context arguments handling when importing from a URL, to address
removal of `cafile`, `capath`, and `cadata` args to `ssl.SSLContext` in Python 3.13.

- Added support for `timeout` argument when importing from a URL. The default value is defined
in the module constant `littletable.DEFAULT_HTTP_TIMEOUT` = 60, but this value can be modified.

- Added exception types to `__all__`.

2.3.3

-------------
- Fixed bug when using `all` on an indexed field (values would be reported in key
order, not in the order they would be found in the table).

- Importing from `.tar.gz` archives added.

- Importing from `.zip`, `.gz`, and `.tar.gz` archives is more tolerant of the
archive file name not exactly matching the compressed contents file name,
as long as the archive contains only one file.

- Added support for wild card transforms in `csv_import`, using "*" as the transform
key. Import data files that have many numeric columns will be able to define a
wild card transform, rather than having to list all the numeric columns.

Instead of:

data = """\
label,a,b,c
A,1,2,3
B,4,5,6
"""
table = littletable.csv_import(data, transforms={"a": int, "b": int, "c": int})

you can write:

table = littletable.csv_import(data, transforms={"*": int})

"*" will try to convert all fields that are not otherwise listed with transforms,
and if an exception occurs (as would happen when trying to do `int()` on a `label`
value), leaves the field's value as-is.

More information on this feature in `how_to_use_littletable.md`.

- Extended `Table.compute_field` to accept just a str argument, naming an existing
field. Use this to add a field name that is an easily referenced Python identifier
with the same values as an existing field name, that might have embedded spaces,
punctuation characters, etc.

table.compute_field("caloric_value", "Caloric Value")

- Added `food_data.py` example, working with CSV files downloaded from Kaggle.

2.3.2

-------------
- Renamed `Table.add_field` to `Table.compute_field`, to better reflect that it
can be used to compute a new field, or overwrite the current values for that
field for all the rows in the table, and is not just for adding new fields.

`Table.add_field` will be retained as a compatibility synonym.

2.3.1

-------------
- Added `Table.batched`, similar to `itertools.batched` added in Python 3.12. Returns
a generator that yields tables sliced into n-sized batches:

for mini_table in tbl.batched(10):
... work with table containing only 10 entries ...

- Extended arguments support in `Table.splitby` to accept named arguments that define
the predicate splitting function in terms of the specific value of one or more
row attributes:

qa_data, production_assembly_data = data.splitby(
lambda rec: rec.env == "prod" and rec.dept == "assembly"
)

can be written as:

qa_data, production_data = data.splitby(env="prod", dept="assembly")

- Added `using` argument to `Table.create_search_index` to simplify creation of a
search index attribute by using multiple existing attributes. See this example
from the `explore_unicode.py` example:

unicode.create_search_index(
"name_words",
using=["name", "unicode_1_name", "iso10646_comment"],
)

The example creates a new field `name_words` by combining the attributes `name`,
`unicode_1_name`, and `iso10646_comment`, and then builds a search index using
this new field.

2.3.0

-------------
- Implemented `get()` for objects returned by `table.by.<indexname>`, to emulate
`dict.get()` behavior (for unique indexes) and `defaultdict.get()` behavior (for
non-unique indexes). <-- POTENTIAL BREAKING CHANGE

- A new optional `errors` argument added to `Table.splitby` to define what action
to take if an exception occurs while evaluating the predicate function. Valid values
for `errors` are:
True : return exceptions as True
False: return exceptions as False
'discard': do not return table rows that raise exceptions
'return': return a third table containing rows that raise exceptions
'raise': raise the exception

`errors` can also be given as a dict mapping specific Exception types to one of
these 5 values.

The default value for `errors` (if omitted, or if an exception is raised
that is not listed in an `errors` dict), is to discard the row.

- New `attrgetter` function accepts a `defaults` dict argument to fill in missing attributes. Is now
used in `Table` sorting, splitting, and exporting, which would previously raise exceptions if one
or more attributes were missing in any row - now replaces missing attributes with None, or a given
default value. `littletable.attrgetter` is supported as part of the public API.

- Reworked `groupby` to be more similar to `itertools.groupby`, yielding a `(key, Table)` tuple for
each grouped list of rows. Includes an optional `sort` argument to sort the table before grouping,
using the same key attributes or function used for grouping. The previous prototype `groupby`
method has been renamed to `groupby_with_summaries`, as it supports the addition of dynamically
computed summary fields.

- Improved unit tests:
- added testing `Tables` containing `dataclasses` with `slots=True`
- added support for test running using `tox`
- modified tests to support running `tox run-parallel` (generate unique test
server ports for different Python versions)

Page 1 of 8

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.