awkward icon indicating copy to clipboard operation
awkward copied to clipboard

"Stepping stone" modules shouldn't be exposed in the namespace

Open jpivarski opened this issue 7 months ago • 0 comments

We have lots of functions, like ak.sum and ak.concatenate, but we shouldn't be cluttering the namespace with things like ak.ak_sum and ak.ak_concatenate:

print("\n".join(x for x in dir(ak) if x.startswith("ak_")))
ak_all
ak_almost_equal
ak_any
ak_argcartesian
ak_argcombinations
ak_argmax
ak_argmin
ak_argsort
ak_backend
ak_broadcast_arrays
ak_broadcast_fields
ak_cartesian
ak_categories
ak_combinations
ak_concatenate
ak_copy
ak_corr
ak_count
ak_count_nonzero
ak_covar
ak_drop_none
ak_enforce_type
ak_fields
ak_fill_none
ak_firsts
ak_flatten
ak_from_arrow
ak_from_arrow_schema
ak_from_avro_file
ak_from_buffers
ak_from_categorical
ak_from_cupy
ak_from_dlpack
ak_from_feather
ak_from_iter
ak_from_jax
ak_from_json
ak_from_numpy
ak_from_parquet
ak_from_rdataframe
ak_from_regular
ak_full_like
ak_is_categorical
ak_is_none
ak_is_tuple
ak_is_valid
ak_isclose
ak_linear_fit
ak_local_index
ak_mask
ak_max
ak_mean
ak_merge_option_of_records
ak_merge_union_of_records
ak_metadata_from_parquet
ak_min
ak_moment
ak_nan_to_none
ak_nan_to_num
ak_num
ak_ones_like
ak_pad_none
ak_parameters
ak_prod
ak_ptp
ak_ravel
ak_run_lengths
ak_singletons
ak_softmax
ak_sort
ak_std
ak_strings_astype
ak_sum
ak_to_arrow
ak_to_arrow_table
ak_to_backend
ak_to_buffers
ak_to_cupy
ak_to_dataframe
ak_to_feather
ak_to_jax
ak_to_json
ak_to_layout
ak_to_list
ak_to_numpy
ak_to_packed
ak_to_parquet
ak_to_rdataframe
ak_to_regular
ak_transform
ak_type
ak_unflatten
ak_unzip
ak_validity_error
ak_values_astype
ak_var
ak_where
ak_with_field
ak_with_name
ak_with_parameter
ak_without_field
ak_without_parameters
ak_zeros_like
ak_zip
print("\n".join(x for x in dir(ak.str) if x.startswith("akstr_")))
akstr_capitalize
akstr_center
akstr_count_substring
akstr_count_substring_regex
akstr_ends_with
akstr_extract_regex
akstr_find_substring
akstr_find_substring_regex
akstr_index_in
akstr_is_alnum
akstr_is_alpha
akstr_is_ascii
akstr_is_decimal
akstr_is_digit
akstr_is_in
akstr_is_lower
akstr_is_numeric
akstr_is_printable
akstr_is_space
akstr_is_title
akstr_is_upper
akstr_join
akstr_join_element_wise
akstr_length
akstr_lower
akstr_lpad
akstr_ltrim
akstr_ltrim_whitespace
akstr_match_like
akstr_match_substring
akstr_match_substring_regex
akstr_repeat
akstr_replace_slice
akstr_replace_substring
akstr_replace_substring_regex
akstr_reverse
akstr_rpad
akstr_rtrim
akstr_rtrim_whitespace
akstr_slice
akstr_split_pattern
akstr_split_pattern_regex
akstr_split_whitespace
akstr_starts_with
akstr_swapcase
akstr_title
akstr_to_categorical
akstr_trim
akstr_trim_whitespace
akstr_upper

These two sets can be removed without fanfare. (If any users are accessing ak.sum as ak.ak_sum.sum, they should be corrected!)

We should probably also get rid of the visibility of "stepping stone" modules like ak.operations, although this one would require a deprecation cycle because it has been used in our tests, and some users might have adopted it for that reason. It can be deprecated by moving operations to _operations and creating a new operations that provides everything through a __getattr__ (PEP-562) that raises a warning.

Ideally, there should be only one correct path to each public API function.

It would also end up removing this:

https://github.com/scikit-hep/awkward/blob/f9a29effed4998054235649c4ee1dfadc059ede0/src/awkward/init.py#L52-L53

jpivarski avatar Jan 20 '24 19:01 jpivarski