Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAD-NG Features and Compatibility Modes #135

Merged
merged 435 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
435 commits
Select commit Hold shift + click to select a range
3c5c2c3
update that part of the readme with compatibility too
fsoubelet Sep 9, 2024
1c19e6e
update that part of the readme with compatibility too
fsoubelet Sep 9, 2024
318fdb8
ignore type checking import blocks for coverage
fsoubelet Sep 9, 2024
3458ed1
and also these statements
fsoubelet Sep 9, 2024
3389afe
its a start
fsoubelet Sep 9, 2024
3f28a2e
add some to changelog
fsoubelet Sep 9, 2024
b704abf
more info
fsoubelet Sep 9, 2024
a30d03c
add this too
fsoubelet Sep 9, 2024
f845033
rephrase
fsoubelet Sep 10, 2024
784cf43
phrasing again
fsoubelet Sep 10, 2024
f0d1825
rephrasing and table format
fsoubelet Sep 10, 2024
3ec774a
MADNG only and admonition about complex representation
fsoubelet Sep 10, 2024
44d01de
should be almost complete
fsoubelet Sep 11, 2024
f723f62
flaky in object mode
fsoubelet Sep 11, 2024
c4d0e95
small iterations left maybe but let's call this a day
fsoubelet Sep 11, 2024
af2bea5
also exported
fsoubelet Sep 11, 2024
47ad9e3
details
fsoubelet Sep 11, 2024
09f29f8
some rewording
JoschD Sep 13, 2024
732a2a0
forgotten save
JoschD Sep 13, 2024
652778b
more to dooooooo
fsoubelet Sep 13, 2024
780db46
and more
fsoubelet Sep 13, 2024
587a4a6
better installation instructions
fsoubelet Oct 15, 2024
1cd1ca9
replace deprecated sphinx-rtd-theme option 'display_version' (since 3.0)
fsoubelet Oct 15, 2024
6366ccf
formatting
fsoubelet Oct 15, 2024
f42982e
formatting
fsoubelet Oct 15, 2024
cc6011c
expand a tad on validation, add mini section (link) to quickstart
fsoubelet Oct 15, 2024
dc4898d
better explained like this
fsoubelet Oct 15, 2024
e94a069
simpler, faster version of the headers_dict check (waiting for the ex…
fsoubelet Oct 15, 2024
0aad6ef
test for writing of pd dataframe
fsoubelet Oct 15, 2024
bc575c6
and that is done
fsoubelet Oct 15, 2024
a3a917d
specifics and writing without headers
fsoubelet Oct 15, 2024
93baf2f
and specify # is for comment lines
fsoubelet Oct 15, 2024
93a363e
no need for todo file anymore
fsoubelet Oct 15, 2024
a3d6af9
formatting again
fsoubelet Oct 15, 2024
e2de680
list all accepted forms in changelog
fsoubelet Oct 15, 2024
58c1f13
indicate alternate accepted forms here
fsoubelet Oct 15, 2024
694e091
not using this file either
fsoubelet Oct 15, 2024
d075dd2
add admonition about unsupported exotic MAD-NG features
fsoubelet Oct 16, 2024
a0cfb73
compatibility typo
fsoubelet Oct 16, 2024
783b1c1
more typo
fsoubelet Oct 16, 2024
0f2a0fa
out of scope, not necessarily true
fsoubelet Oct 16, 2024
0cdcd03
actually MAD-NG compliant file
fsoubelet Oct 16, 2024
1ff4c89
actually MAD-NG compliant file
fsoubelet Oct 16, 2024
87cb821
actually MAD-NG compliant file
fsoubelet Oct 16, 2024
d090c66
fix example tfs, specify integer type identifier is only MAD-X since …
fsoubelet Oct 16, 2024
d22e036
correct info about the length in type identifier
fsoubelet Oct 16, 2024
98581e3
explain much more for the next devs
fsoubelet Oct 16, 2024
04c6f95
convert integer headers to float in MADNG mode - NEEDS TESTING
fsoubelet Oct 16, 2024
51d0c2c
test for headers conversion in MADNG mode
fsoubelet Oct 16, 2024
1fe1c73
it can be i or I according to Laurent
fsoubelet Oct 16, 2024
e25d53c
change some is to Is in test files
fsoubelet Oct 16, 2024
ab3a152
update compressed versions
fsoubelet Oct 16, 2024
d6506c7
include info about i and I
fsoubelet Oct 16, 2024
6357b7d
default compression extra for pandas, add pymadng in test deps
fsoubelet Oct 16, 2024
5c8899e
correct info since Laurent makes the change to MAD-NG for %XXs
fsoubelet Oct 17, 2024
43f844c
more pythonic
fsoubelet Oct 17, 2024
fc741f8
more sense
fsoubelet Oct 17, 2024
662aec5
extra check in MADX mode for a TYPE headers
fsoubelet Oct 17, 2024
3d31eb1
phrasing
fsoubelet Oct 17, 2024
f5acf3e
specify here that we add a TYPE in MADX mode if not present
fsoubelet Oct 17, 2024
c15c39a
todo
fsoubelet Oct 17, 2024
29b5139
remove tfs doc info about %d and MADNG as it will be handled next rel…
fsoubelet Oct 18, 2024
2e25e70
TEMPORARY - Accept %i for integer identifier when reading, with TODO
fsoubelet Oct 18, 2024
baa5c4b
we don't have to convert int headers to float anymore as MADNG will a…
fsoubelet Oct 18, 2024
eec2834
which means this test goes away too
fsoubelet Oct 18, 2024
15adca2
some info here
fsoubelet Oct 18, 2024
6dea357
add todo to be replaced when we have info on the next released MAD-NG…
fsoubelet Oct 18, 2024
e6a1e7b
with next MADNG release this is both MADX and MADNG
fsoubelet Oct 18, 2024
bf4d153
some todo and tentative %i addition
fsoubelet Oct 18, 2024
84e8d71
some todo
fsoubelet Oct 18, 2024
8876bc7
todo
fsoubelet Oct 18, 2024
e1d2665
do it now - move these warning tests to validation as that's what is …
fsoubelet Oct 18, 2024
b815e28
and reformat
fsoubelet Oct 18, 2024
2f7fcec
skeleton for pymadng test
fsoubelet Oct 18, 2024
fc5794e
its a nope on the %i for integers
fsoubelet Oct 18, 2024
eaf534a
it's the default anyway
fsoubelet Oct 18, 2024
354f003
willing to demonstrate uv
fsoubelet Oct 18, 2024
45f3086
last test
fsoubelet Oct 18, 2024
991a4c3
with updates there
fsoubelet Oct 18, 2024
3f21006
back to master
fsoubelet Oct 18, 2024
e19af1f
Implement review suggestion
fsoubelet Oct 22, 2024
7bc9444
revert this too
fsoubelet Oct 22, 2024
0dfd26c
suggestions
fsoubelet Oct 22, 2024
ac5e3b3
suggestions
fsoubelet Oct 22, 2024
5425911
point to the doc page for TFS
fsoubelet Oct 22, 2024
d52e483
adding 91 ref
fsoubelet Oct 22, 2024
ee9b97e
suggestions
fsoubelet Oct 22, 2024
841a857
suggestions
fsoubelet Oct 22, 2024
a4d5860
suggestions
fsoubelet Oct 22, 2024
6274b77
suggestions
fsoubelet Oct 22, 2024
8bdea97
suggestions
fsoubelet Oct 22, 2024
51f621a
suggestions, check string dtype here
fsoubelet Oct 22, 2024
56c3962
should be an or here
fsoubelet Oct 22, 2024
e519646
suggestions
fsoubelet Oct 22, 2024
c83a34c
suggestions
fsoubelet Oct 22, 2024
ecc4dfb
use _parse_complex, add comments
fsoubelet Oct 22, 2024
ef7c09c
suggestions
fsoubelet Oct 22, 2024
1dcc9b2
suggestions
fsoubelet Oct 22, 2024
e46e495
suggestions
fsoubelet Oct 22, 2024
95d1935
suggestions
fsoubelet Oct 22, 2024
e4dafae
fix duplicate
fsoubelet Oct 22, 2024
b70b6cb
adapt docstring for validate
fsoubelet Oct 22, 2024
b2d8fec
skip validation on None only
fsoubelet Oct 22, 2024
c2c6a54
these should then be None
fsoubelet Oct 22, 2024
0f28ceb
suggestions
fsoubelet Oct 22, 2024
7c59cd2
suggestions
fsoubelet Oct 22, 2024
38c7a8f
SUPPORTED_EXTENSIONS constant
fsoubelet Oct 22, 2024
ce93229
should handle Path?
fsoubelet Oct 22, 2024
bce772b
only cast the Paths
fsoubelet Oct 22, 2024
3cec9df
add validation trigger tests from reader and writer
fsoubelet Oct 22, 2024
07a83b0
do not expand path form when converting
fsoubelet Oct 22, 2024
1def6b1
rename formatter class
fsoubelet Oct 22, 2024
67e2880
membership test should be not in
fsoubelet Oct 22, 2024
f90b9e5
unused imports
fsoubelet Oct 22, 2024
4b4e80d
more explicit, above comment
fsoubelet Oct 22, 2024
ca138b3
be a bit more explicit here too
fsoubelet Oct 22, 2024
89ffc9a
boop
fsoubelet Oct 22, 2024
164185f
another comment gone
fsoubelet Oct 22, 2024
e44e7d2
backticks for my boii
fsoubelet Oct 22, 2024
9726187
include tables in that admonition too
fsoubelet Oct 22, 2024
54071e7
clearer names here
fsoubelet Oct 22, 2024
dac0508
more explicit here too
fsoubelet Oct 22, 2024
21f7819
add raise info to docstring
fsoubelet Oct 22, 2024
a7f9506
more docstring info
fsoubelet Oct 22, 2024
e550017
some more comments
fsoubelet Oct 22, 2024
549ffad
propagate the function namechange here too
fsoubelet Oct 22, 2024
716bc5a
comment again
fsoubelet Oct 22, 2024
b52b7ac
accept nil as a NaN value
fsoubelet Oct 22, 2024
416d5a8
add some nil here
fsoubelet Oct 22, 2024
9652f17
comment about the nils
fsoubelet Oct 22, 2024
7cda8c9
more comment
fsoubelet Oct 22, 2024
ca501a5
should be only nans here
fsoubelet Oct 22, 2024
c8924a4
we can now handle NaN and nil in the headers too, so reader is ok
fsoubelet Oct 22, 2024
bb3b132
add tests for reading nil in headers and in data
fsoubelet Oct 22, 2024
be7675e
add test file with nils
fsoubelet Oct 22, 2024
931fef1
also check headers values for unphysical ones
fsoubelet Oct 22, 2024
0c3adc7
and a test for it
fsoubelet Oct 22, 2024
58a2795
properly return %n for nan/nil dtypes
fsoubelet Oct 22, 2024
bd2a8e8
more info
fsoubelet Oct 22, 2024
401a60b
only nils in here
fsoubelet Oct 22, 2024
fa377bb
have NoneType in here for %n
fsoubelet Oct 22, 2024
84297a0
infer from NoneType to return None
fsoubelet Oct 22, 2024
4316702
fix behaviour in tests - headers cast to None, data to NaN
fsoubelet Oct 22, 2024
05b84c0
should work on 3.9 too
fsoubelet Oct 22, 2024
6d18ee5
also no need for NoneType here
fsoubelet Oct 22, 2024
45bb12b
docstring fix
fsoubelet Oct 22, 2024
e7ea2f9
nil is NoneType
fsoubelet Oct 22, 2024
7a9cc9e
admonition here about nullable behaviour in tfspandas
fsoubelet Oct 22, 2024
93bb4c7
this should be an empty line
fsoubelet Oct 22, 2024
e4b2629
correct info here
fsoubelet Oct 22, 2024
ec065d8
nil tests comments correction, check all columns with nils
fsoubelet Oct 22, 2024
bd1303a
correct this
fsoubelet Oct 22, 2024
2239466
simple nan in headers validation
fsoubelet Oct 22, 2024
a7aac7f
more info about the NaN in numeric columns
fsoubelet Oct 22, 2024
e2da112
more comment
fsoubelet Oct 22, 2024
7d5d019
intercept None values actually for %n and nil
fsoubelet Oct 22, 2024
8e8bd58
special handling of nullables, can write %n nil just fine in headers …
fsoubelet Oct 22, 2024
c406a54
info
fsoubelet Oct 22, 2024
28a2f60
writes None in columns as nil properly but formatting is messed up
fsoubelet Oct 22, 2024
b366443
None making its way into a non-numeric column will be written out as …
fsoubelet Oct 22, 2024
a0a34ee
this commented out path goes away
fsoubelet Oct 22, 2024
3ad13c4
fix TITLE in this test file
fsoubelet Oct 22, 2024
a0aae19
add nullable support of nils in changelog
fsoubelet Oct 22, 2024
378b14a
one more comment
fsoubelet Oct 23, 2024
fd9789d
as note
fsoubelet Oct 23, 2024
82d66d8
this was just not true I handle it fine
fsoubelet Oct 23, 2024
99f0914
properly read empty strings and cast nils in string columns to None
fsoubelet Oct 23, 2024
adc8b8e
be super specific here
fsoubelet Oct 23, 2024
2c7edae
also test for nil in string column
fsoubelet Oct 23, 2024
da6db00
test writing with None (to nil) in headers
fsoubelet Oct 23, 2024
5e8bcea
that was a duplicate
fsoubelet Oct 23, 2024
e44191b
add test for pathlib.Path in headers handled properly and written as …
fsoubelet Oct 23, 2024
dda2277
comments
fsoubelet Oct 23, 2024
61fde0f
disallow None in headers for MAD-X mode
fsoubelet Oct 23, 2024
3102427
comments
fsoubelet Oct 23, 2024
21bf806
and add a test for this
fsoubelet Oct 23, 2024
a1b4aba
some more info in CHANGELOG
fsoubelet Oct 24, 2024
c2f211a
some linting
fsoubelet Oct 24, 2024
5bc250d
better than concatenation, better than try return
fsoubelet Oct 24, 2024
c238b3d
match on raised error, use fixture
fsoubelet Oct 24, 2024
ddc79c4
unecessary elifs with returns in ifs
fsoubelet Oct 24, 2024
45f8ef7
add todo so I can switch branches
fsoubelet Nov 14, 2024
2aa1dcf
merge master back into madng
fsoubelet Nov 14, 2024
3d27744
remove unused
fsoubelet Nov 14, 2024
aa85414
use the testing helper from our own module now
fsoubelet Nov 14, 2024
1cfbb21
min pymadng version is 0.5.0 for our tests
fsoubelet Dec 5, 2024
85cddfc
specify minimum MADNG version for compatibility
fsoubelet Dec 5, 2024
5481cd5
no cern network tests here
fsoubelet Dec 5, 2024
2c3d2db
test for madng reading our files
fsoubelet Dec 5, 2024
0cb944e
we skip this test on Windows as pymadng and MADNG are not available t…
fsoubelet Dec 5, 2024
569876b
require pymadng version with exposed protected_send
fsoubelet Dec 6, 2024
815d3d2
drop python 3.9, resolve the dependency constraints on numpy 2 and py…
fsoubelet Dec 13, 2024
acef0d9
can import and use NoneType since we drop python3.9
fsoubelet Dec 13, 2024
414b107
can import and use NoneType since we drop python3.9
fsoubelet Dec 13, 2024
21d4ab5
update the changelog with relevant version numbers
fsoubelet Dec 13, 2024
ca76aae
don't need this todo file, was just for me
fsoubelet Dec 13, 2024
bca4e06
don't need this todo file, was just for me
fsoubelet Dec 13, 2024
92abaef
NAME example is a string
fsoubelet Dec 13, 2024
a262f1c
no need for protected_send anymore
fsoubelet Dec 13, 2024
9ec21c0
less verbose
fsoubelet Dec 13, 2024
ab75b1a
more explicit on behaviour regarding headers_dict, the df headers, or…
fsoubelet Dec 13, 2024
a2aaf51
add comment about why we use pandas.read_csv in _read_metadata too
fsoubelet Dec 13, 2024
d87611c
test content of table written then read by MAD-NG
fsoubelet Dec 13, 2024
e5a944e
testing josch idea
fsoubelet Dec 13, 2024
3604f54
slightly cleaner version
fsoubelet Dec 13, 2024
dec0f24
fully replace old _read_metadata
fsoubelet Dec 13, 2024
8020533
explicit rename of helper
fsoubelet Dec 13, 2024
cc4b97a
no need to recv as we communicate later
fsoubelet Dec 13, 2024
7184132
finalize docstrings for new helpers
fsoubelet Dec 13, 2024
3aa112c
do not use anymore this unexpected sep
fsoubelet Dec 13, 2024
d2a5baf
some final linting
fsoubelet Dec 13, 2024
ca58fe5
some small pytest config to get coverage info
fsoubelet Dec 13, 2024
91f7d48
change affiliation because why not
fsoubelet Dec 13, 2024
cb0929a
we should test writing with NO HEADERS for all validation modes
fsoubelet Dec 16, 2024
da2acb8
dummy guards checking headers exist before manipulating them
fsoubelet Dec 16, 2024
95b82ac
with a helper function and a bit more checks
fsoubelet Dec 16, 2024
035f497
check they're here, error if not in MADX mode
fsoubelet Dec 16, 2024
f1921c7
this only checks in no validation and MADNG validation modes
fsoubelet Dec 16, 2024
7cd5ece
add a check for expected failure in MAD-X mode for this case
fsoubelet Dec 16, 2024
005cc8c
document edge case about no headers in MADX compatibility mode
fsoubelet Dec 16, 2024
eec3566
and document the step in the docstring of validation function
fsoubelet Dec 16, 2024
54e0620
where did that come from
fsoubelet Dec 16, 2024
ee0cb7f
add this to the changelog
fsoubelet Dec 16, 2024
c9de62b
not needed with new behaviour
fsoubelet Dec 18, 2024
ac63358
cast to TfsDataFrame in any case and make sure there are headers
fsoubelet Dec 18, 2024
05ed77c
and check for this in validation
fsoubelet Dec 18, 2024
2f776e5
dq
fsoubelet Dec 18, 2024
ff7caaa
docpage for validation off by default
fsoubelet Dec 18, 2024
cabddb5
also in the changelog
fsoubelet Dec 18, 2024
8bbcbac
still mention it is default in validation function itself
fsoubelet Dec 18, 2024
8be5b73
validation is OFF by default when writing
fsoubelet Dec 18, 2024
be6f123
adapt writer tests to explicitely ask for validation when it was impl…
fsoubelet Dec 18, 2024
776ae4b
NoneType also here
fsoubelet Dec 18, 2024
58e02e8
just comments
fsoubelet Dec 18, 2024
210ca74
remove this comment block
fsoubelet Dec 18, 2024
351d0e5
spaces and consistency
fsoubelet Dec 18, 2024
a05b82a
no emojis
fsoubelet Dec 18, 2024
21cfb50
showcase headers are here
fsoubelet Dec 18, 2024
03152f8
correct function names in documentation examples
fsoubelet Dec 18, 2024
eea534b
fix the rounding issues in headers
fsoubelet Dec 18, 2024
e7763e0
this is not used anymore
fsoubelet Dec 19, 2024
5ca050a
comments
fsoubelet Dec 19, 2024
01ce775
add a None (becomes nil) in the _tfs_dataframe_madng fixture
fsoubelet Dec 19, 2024
82b1e72
clearer name for helper function
fsoubelet Dec 19, 2024
63df6cf
examples reworked for new behaviour
fsoubelet Dec 20, 2024
36abd0a
update docstring on the validate argument
fsoubelet Dec 20, 2024
f9d39b6
backwards compatible check
fsoubelet Dec 20, 2024
d56e9e2
test for pd.DataFrame + headers provided to writing
fsoubelet Dec 20, 2024
ade7a2f
more accurate test names
fsoubelet Dec 20, 2024
fc12167
parametrize validation modes, check that providing dataframe with emp…
fsoubelet Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
uses: pylhc/.github/.github/workflows/coverage.yml@master
with:
src-dir: tfs
pytest-options: -m "not cern_network" --cov-report term-missing
pytest-options: --cov-report term-missing
secrets: inherit
3 changes: 1 addition & 2 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Runs all tests on master on Mondays at 3 am (UTC time)
name: Cron Testing


on:
on:
schedule:
- cron: '* 3 * * mon'

Expand Down
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"name": "Felix Soubelet",
"affiliation": "University of Liverpool & CERN",
"affiliation": "CERN",
"orcid": "0000-0001-8012-1440"
},
{
Expand Down
34 changes: 33 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# TFS-Pandas Changelog

## Version 4.0.0

Version `4.0` is a major release bringing compatibility with `MAD-NG` features in **TFS** files and tables, apart from the more exotic ones.
We also bring new documentation pages regarding the **TFS** format, code compatibilities, and the new features.
Please have a look at the documentation should you intent to use `tfs-pandas` 4.0, as there are a few (now documented) caveats.

- Important:
- Support for `Python 3.9` has been dropped. The minimum required Python version is now `3.10`.
- DataFrame validation is now OFF by default, both when reading from and writing to file. It is up to the user to ask for a given validation mode.
- Minimum supported `MAD-NG` version is `1.0.0`, due to synchronized development of some feature details. The corresponding `pymadng` version is `0.6.0`.

- Added:
- Handling of boolean-type and complex-type header values (`MAD-NG` feature).
- Handling of bolean-type and complex-type columns (`MAD-NG` feature).
- Handling of nullable-type `nil` values in headers and columns (`MAD-NG` feature).
- Compatibility modes for dataframe validation. The `tfs.frame.validate` function now expects this, and valid choices are `MADX`, `MAD-X`, `MADNG` and `MAD-NG` (case-insensitive, see API documentation).
- Many new exceptions have been created for raised errors, which will be more specific. They all inherit from the previously raised `TfsFormatError`, so user code that was catching it will still work.

fsoubelet marked this conversation as resolved.
Show resolved Hide resolved
- Changed:
- By default, `TfsDataFrame` validation is now skipped on reading.
- By default, `TfsDataFrame` validation is now skipped on writing.
- By default, `TfsDataFrame` validation in `MAD-X` requires headers to be present in the dataframe.

- Fixed:
- Writing a dataframe with no headers (not empty headers), e.g. a `pandas.DataFrame` - now works correctly.

- Documentation:
- The documentation has been updated to reflect the new features and changes.
- The documentation now includes a new page on the `TFS` format itself.
- The documentation now includes a new page on compatibility modes for `TfsDataFrame` validation.
- A great deal of internal documentation has been added to the codebase.

## Version 3.9.0

- Added:
Expand Down Expand Up @@ -93,7 +125,7 @@ Minor API changes to the `TFSCollections`:
## Version 3.5.2

- Changed:
- The dependency on `pandas` has been pinned to `<2.0` to guarantee the proper functionning of the compability `append` and `join` methods in `TfsDataFrames`. These will be removed with the next release of `tfs-pandas` and users should use the `tfs.frame.concat` compatibility function instead.
- The dependency on `pandas` has been pinned to `<2.0` to guarantee the proper functionning of the compatibility `append` and `join` methods in `TfsDataFrames`. These will be removed with the next release of `tfs-pandas` and users should use the `tfs.frame.concat` compatibility function instead.

## Version 3.5.1

Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
[![Conda-forge Version](https://img.shields.io/conda/vn/conda-forge/tfs-pandas?color=orange&logo=anaconda)](https://anaconda.org/conda-forge/tfs-pandas)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5070986.svg)](https://doi.org/10.5281/zenodo.5070986)

This package provides reading and writing functionality for [**Table Format System (TFS)** files](http://mad.web.cern.ch/mad/madx.old/Introduction/tfs.html).
Files are read into a `TfsDataFrame`, a class built on top of the famous `pandas.DataFrame`, which in addition to the normal behavior attaches a dictionary of headers to the `DataFrame`.
This package provides reading and writing functionality for [**Table Format System (TFS)**](https://pylhc.github.io/tfs/tfsformat.html) files.
Files are read into a `TfsDataFrame`, a class built on top of the `pandas.DataFrame`, which in addition to the normal behavior attaches a dictionary of headers to the `DataFrame`.

See the [API documentation](https://pylhc.github.io/tfs/) for details.

Expand Down Expand Up @@ -45,14 +45,19 @@ data_frame.headers["NEW_KEY"] = some_variable
# Manipulate data as you do with pandas DataFrames
data_frame["NEWCOL"] = data_frame.COL_A * data_frame.COL_B

# You can check the validity of a TfsDataFrame, and choose the behavior in case of errors
tfs.frame.validate(data_frame, non_unique_behavior="raise") # or choose "warn"
# You can check the validity of a TfsDataFrame, speficying the
# compatibility mode as well as the behavior in case of errors
tfs.frame.validate(
data_frame,
non_unique_behavior="raise", # or choose "warn"
compatibility="mad-x", # or choose "mad-ng"
)
fsoubelet marked this conversation as resolved.
Show resolved Hide resolved

# Writing out to disk is simple too
tfs.write("path_to_output.tfs", data_frame, save_index="index_column")
```

Reading and writing compressed files is also supported, and done automatically based on the provided file extension:
Compression is automatically supported, based on the provided file extension (for supported formats):

```python
import tfs
Expand Down
101 changes: 101 additions & 0 deletions doc/compatibility.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
MAD-X and MAD-NG Compatibility
==============================

As `tfs-pandas` allows one to write `TfsDataFrames` as files in the **TFS** format, which are typically output by simulations codes, compatibility of these files with said codes is crucial.
Specifically, `tfs-pandas` aims to ensure the files it writes to disk are accepted as input for `MAD-X <https://madx.web.cern.ch/>`_ and `MAD-NG <https://madx.web.cern.ch/releases/madng/html/>`_.

However, as ``MAD-NG`` is the successor to ``MAD-X``, it includes new features regarding the **TFS** format, and files including these features will not be accepted by ``MAD-X``.
To circumvent this issue, `tfs-pandas` offers functionality - named validation - to ensure compatibility with either code.

TfsDataFrame Validation
-----------------------

It is possible to perform automatic validation of a `TfsDataFrame` both when reading and writing, or to validate them at any time using the `tfs.frame.validate` function.
Validation enforces the rules described in the :ref:`caveats section <tfs-pandas caveats>`, both to guarantee the integrity of the dataframe and compatibility of written files with simulation codes.

.. admonition:: When Does Validation Happen?

Validation is **optional**, and is by default turned off at both read-time and write-time.

Validation is done by providing a `TfsDataFrame` and a compatibility mode to `tfs.frame.validate` (see the :ref:`API reference <modules/index:frame>`).
It goes as:

.. code-block:: python

import tfs
from tfs.frame import validate

df = tfs.read("path/to/file.tfs")

# To validate with MAD-X compatibility
validate(df, compatibility="mad-x") # or use "madx"

# To validate with MAD-NG compatibility
validate(df, compatibility="mad-ng") # or use "madng"

In case of compatibility issue, an exception is raised which will point to the specific incompatible element.
All exceptions inherit from the `TfsFormatError`, which one can `except` as a catch-all for this package.

.. _common rules:

Common Validation Rules
-----------------------

In either compatibility mode, some common rules are enforced.
These rules are listed and described in the :ref:`API reference <modules/index:frame>` for the `tfs.frame.validate` function.

When validating a `TfsDataFrame`, the behavior in case one of these rules is violated depends on the value of the `non_unique_behavior` parameter.
These rules are *always* checked against when validating a `TfsDataFrame`.
Additional checks can be performed by setting the `compatibility` parameter, as described in the :ref:`MAD-NG <madng mode>` and :ref:`MAD-X <madx mode>` below.

.. _madng mode:

MAD-NG Compatibility
--------------------

.. admonition:: Supported Versions

The compatibility with ``MAD-NG`` is guaranteed starting with version `1.0.0`.
See below for details and caveats.

Since ``MAD-NG`` implements and accepts more features into its **TFS** files, its compatibility mode is naturally less restrictive.
Namely, the following are accepted by ``MAD-NG`` and ``MAD-NG`` only:

- Boolean dtype for header parameters and table columns.
- Complex dtype for header parameters and table columns.
- Nullable dtype for header parameters and table columns (value `nil`).

.. admonition:: Complex Number Representation

In Python, the imaginary part of a complex number is represented by the letter ``j``, as in `1.4 + 2.6j`.
When writing complex values to file, `tfs-pandas` will instead use the ``MAD-NG`` (read `Lua`) representation, and uses the letter ``i``, as in `1.4 + 2.6i`, so that ``MAD-NG`` can properly read such a file.
Both of these representations will be correctly read by `tfs-pandas` (including when ``MAD-NG`` uses ``I`` for special complex numbers).

.. admonition:: Handling of Nullable Types

``MAD-NG`` uses the nullable `nil`, which is accepted by `tfs-pandas` with the following caveats:

- When reading from file, `nil` values in the headers are converted to `None` while those in the dataframe are cast to `NaN`, except in string-dtyped columns where they are converted to `None`.
- When writing to file, `None` values anywhere are written as `nil`, and `NaN` values in the dataframe are written as `NaN` (remember that setting a `None` in a numeric `pandas.DataFrame` column automatically casts it as `NaN`).

.. attention::

The exotic "features" of ``MAD-NG`` such as the ``Lua`` operator overloading for ranges and tables, and their inclusion in **TFS** files are not supported by `tfs-pandas`.
Should one need to use these features, it is recommended to go through the `pymadng <https://pymadng.readthedocs.io/en/latest/>`_ package to handle them in-memory.

.. _madx mode:

MAD-X Compatibility
-------------------

The ``MAD-X`` compatibility mode is more restrictive, and enforces that none of the features listed in the :ref:`MAD-NG section <madng mode>` appear in the `TfsDataFrame`.

Additionally, ``MAD-X`` will refuse to read into a table any **TFS** file that does not include a `TYPE` entry in the headers (which should be a string).
As such, when checking for compatibility with ``MAD-X``:

- If the dataframe has no headers, an error will be raised indicating the dataframe should have headers.
- If the dataframe has headers but no `TYPE` entry is not found, `tfs-pandas` will log a warning and add one with the value `"Added by tfs-pandas for MAD-X compatibility"`

.. admonition:: Default mode

The default compatibility mode enforced by the `tfs.frame.validate` function is ``MAD-X``.
5 changes: 3 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict:
# ones.
extensions = [
"sphinx.ext.autodoc", # Include documentation from docstrings
"sphinx.ext.autosectionlabel", # Create explicit doc targets for each section
fsoubelet marked this conversation as resolved.
Show resolved Hide resolved
"sphinx.ext.coverage", # Collect doc coverage stats
"sphinx.ext.doctest", # Test snippets in the documentation
"sphinx.ext.githubpages", # Publish HTML docs in GitHub Pages
Expand All @@ -64,7 +65,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict:
]

# Config for autosectionlabel extension
autosectionlabel_prefix_document = True
autosectionlabel_prefix_document = True # Make sure the target is unique
autosectionlabel_maxdepth = 2

# Config for the napoleon extension
Expand Down Expand Up @@ -138,7 +139,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict:

html_theme_options = {
"collapse_navigation": False,
"display_version": True,
"version_selector": True, # replaces 'display_version' since sphinx-rtd-theme 3.0 but only works on ReadTheDocs
"logo_only": True,
"navigation_depth": 3,
}
Expand Down
13 changes: 8 additions & 5 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
Welcome to tfs-pandas' documentation!
=====================================

``tfs-pandas`` is a library for reading and writing capabilities for `TFS files <http://mad.web.cern.ch/mad/madx.old/Introduction/tfs.html>`_ used at `CERN <https://home.cern/>`_.
``tfs-pandas`` is a library for reading and writing capabilities for **TFS** files used at `CERN <https://home.cern/>`_, namely by codes such as `MAD-X <https://madx.web.cern.ch/>`_ and `MAD-NG <https://madx.web.cern.ch/releases/madng/html/>`_.

It provides functionality through a ``TfsDataFrame`` object, an extension of the popular **pandas** ``DataFrame``, which in addition to the normal behaviour attaches a dictionary of headers to the ``DataFrame``.
It provides functionality through a ``TfsDataFrame`` object, an extension of the popular **pandas** ``DataFrame``, which in addition to the normal behaviour attaches a dictionary of headers to the dataframe.
Functions are also exported that handle reading and writing of **TFS** files to and from ``TfsDataFrames`` as well as merging and validating for ``TfsDataFrames``.

.. admonition:: **Package Scope**

The package only has as a goal to provide a simple and easy to use interface from **TFS** files to a familiar object build upon the `pandas.DataFrame`.
It is not meant to implement various calculations on `TfsDataFrames`.

Tools relative to the **TFS** format are provided, such as validating a `~.TfsDataFrame` and its headers; or lazily manage a collection of **TFS** files.
Tools relative to the **TFS** format are provided, such as validating a `TfsDataFrame` and its headers; or lazily managing a collection of **TFS** files.


Installation
============

Installation is easily done via `pip`:
The package is published on `PyPI` and installation is easily done via `pip`:

.. code-block:: bash

python -m pip install tfs-pandas

One can also install in a `conda`/`mamba` environment via the `conda-forge` channel with:
There is also a maintained version of the package on `conda-forge`.
One can install in a `conda`/`mamba` environment via the `conda-forge` channel with:

.. code-block:: bash

Expand All @@ -40,6 +41,8 @@ Contents
:maxdepth: 2

quickstart
tfsformat
compatibility
modules/index


Expand Down
29 changes: 17 additions & 12 deletions doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
Yes, 2 minutes.
That's how little it takes!

.. hint::

You can click the function names in the code examples below to go directly to their documentation.

Basic Usage
-----------

Expand Down Expand Up @@ -44,7 +40,7 @@ Compression

A **TFS** file being text-based, it benefits heavily from compression.
Thankfully, `tfs-pandas` supports automatic reading and writing of various compression formats.
Just use the API as you would normally, and the compression will be handled automatically:
Just use the API as you would normally, and the compression will be handled automatically based on the extension:

.. autolink-preface:: import tfs
.. code-block:: python
Expand All @@ -60,7 +56,7 @@ First though, one needs to install the package with the `hdf5` extra requirement

.. code-block:: bash

python -m pip install --upgrade tfs-pandas[hdf5]
python -m pip install --upgrade "tfs-pandas[hdf5]"
fsoubelet marked this conversation as resolved.
Show resolved Hide resolved

Then, access the functionality from `tfs.hdf`.

Expand All @@ -70,13 +66,22 @@ Then, access the functionality from `tfs.hdf`.
from tfs.hdf import read_hdf, write_hdf

# Read a TfsDataFrame from an HDF5 file
df = tfs.hdf.read("path_to_input.hdf5", key="key_in_hdf5_file")
df = tfs.hdf.read_hdf("path_to_input.hdf5", key="key_in_hdf5_file")

# Write a TfsDataFrame to an HDF5 file
tfs.hdf.write("path_to_output.hdf5", df, key="key_in_hdf5_file")
tfs.hdf.write_hdf("path_to_output.hdf5", df, key="key_in_hdf5_file")

Validation
----------

As **TFS** files typically come from the output of simulations codes, validation modes are available to ensure compatibility with said codes.
This is done through the `tfs.frame.validate` function, or relevant arguments in both the reader and writer functions.

As validation modes and compatibility details are complex, validation warrants its own documentation page.
Please refer to the :doc:`compatibility and validation guide <compatibility>` for more information.
fsoubelet marked this conversation as resolved.
Show resolved Hide resolved

Compatibility
-------------
Function Replacements
---------------------

Finally, some replacement functions are provided for some `pandas` operations which, if used, would return a `pandas.DataFrame` instead of a `~.TfsDataFrame`.

Expand All @@ -89,9 +94,9 @@ Finally, some replacement functions are provided for some `pandas` operations wh
# This returns a pandas.DataFrame and makes you lose the headers
result = pd.concat([df1, df2])

# Instead, use our own
# Instead, use our own wrapper
result = tfs.frame.concat([df1, df2]) # you can choose how to merge headers too
assert isinstance(result, tfs.TfsDataFrame) # that's ok!
assert getattr(result, "headers", None) is not None # headers are not lost

That's it!
Happy using :)
Loading
Loading