Saravanan666/pypi-org huggingface dataset:
Package: polars_bin2
polars bin2An enhancedbinnamespace for polars.The polarsstrnamespace contains many functions that would also be useful to have in thebinnamespace. Thepolars_bin2package implements these functions in thebin2namespace for both Series and Expr in polars.Most of the functions inpolars_bin2are currently implemented by 1) encoding binary data asstr, 2) using thestrnamespace, and 3) converting the result approximately.Example UsageImportingpolars_bin2registers the namespace.importpolars_bin2addresses=[b'\xda\xc1\x7f\x95\x8d.\xe5#\xa2b\x06\x99E\x97\xc1=\x83\x1e\xc7',b'\xa0\xb8i\x91\xc6!\x8b6\xc1\xd1\x9dJ.\x9e\xb0\xce6\x06\xebH',b'_\x98\x80ZN\x8b\xe2U\xa3(\x80\xfd\xec\x7fg(\xc6V\x8b\xa0']series=pl.Series('address',addresses)print(series.bin2.lengths())Available functions in each namespace(as of polars 0.18.13)functionstrbinbin2descriptionconcat✅❌✅concatenate series into single valuecontains✅✅✅check if value contains subvaluecount_match✅❌✅count number of occurencesdecode✅✅✅decode using provided encodingencode✅✅✅encode using provided encodingends_with✅✅✅check if value ends with subvaluelengths✅❌✅return byte length of each entryljust✅❌✅left justify according towidthreplace✅❌✅replace first subvalue occurence with new valuereplace_all✅❌✅replace all subvalue occurences with new valuerjust✅❌✅right justify according towidthslice✅❌✅create subslices of each valuesplit✅❌✅split each value by a subvaluestarts_with✅✅✅check if value starts with subvaluezfill✅❌✅fill the value with zerosStrip functions cannot be implemented because strip works on single chars andbin-strencodings do not have a 1:1 mapping of bytes to chars. For example, using a hex encoding could remove an extra zero, making the encoding invalid, whereas base64 encoding does not have a 1:1 mapping of chars to bytes.functionstrbinbin2descriptionlstrip✅❌❌remove leading subvaluesrstrip✅❌❌remove trailing subvaluesstrip✅❌❌remove leading and trailing subvaluesThere are some other functions in thestrnamespace that are not applicable to binary data. These are not currently implemented inbin2, though there might be some reason to implement them in the future:functionstrbinbin2descriptionexplode✅❌❌return separate row for each subvalueextract✅❌❌extract target group from provided patternextract_all✅❌❌extract all matches for provided patternextract_groups✅❌❌extract all groups for provided patternjson_extract✅❌❌parse values as jsonjson_path_match✅❌❌extract first match of JSON stringn_chars✅❌❌return char length of each entryparse_int✅❌❌parse integerssplit_exact✅❌❌split each value by a subvalue usingnsplitssplitn✅❌❌split each value by a subvalue at mostntimesstrptime✅❌❌convert to a date/time columnto_date✅❌❌convert to a date columnto_datetime✅❌❌convert to a time columnto_decimal✅❌❌convert to a decimal columnto_lowercase✅❌❌convert to lowercaseto_time✅❌❌convert to a time columnto_titlecase✅❌❌convert to title caseto_uppercase✅❌❌convert to upper case
Package: polars-business
Polars-businessBusiness day utilities forPolars.✅ blazingly fast, written in Rust!✅ seamless Polars integration!✅ define your own custom holidays and weekends!InstallationFirst, you need toinstall Polars.Then, you'll need to installpolars-business:pip install polars-businessThen, if you can runfromdatetimeimportdateimportpolars_businessasplbprint(plb.date_range(date(2023,1,1),date(2023,1,10),eager=True))it means installation all worked correctly!Read thedocumentationfor a little tutorial and API reference.Basic ExampleSay we start withfromdatetimeimportdateimportpolarsasplimportpolars_businessasplbdf=pl.DataFrame({"date":[date(2023,4,3),date(2023,9,1),date(2024,1,4)]})Let's shiftDateforwards by 5 days, excluding Saturday and Sunday:result=df.with_columns(date_shifted=plb.col("date").bdt.offset_by('5bd',weekend=('Sat','Sun'),))print(result)shape: (3, 2)
┌────────────┬──────────────┐
│ date       ┆ date_shifted │
│ ---        ┆ ---          │
│ date       ┆ date         │
╞════════════╪══════════════╡
│ 2023-04-03 ┆ 2023-04-10   │
│ 2023-09-01 ┆ 2023-09-08   │
│ 2024-01-04 ┆ 2024-01-11   │
└────────────┴──────────────┘You can also count the number of business days between two given dates, specify a custom
calendar holiday, and create a date range excluding workdays.Read thedocumentationfor more examples!PerformanceSingle-threaded performance is:about on par with NumPy (it's essentially a Rust reimplementation)about an order of magnitude faster than pandas.but note that Polars will take care of parallelisation for you, and that this plugin
will fit in with Polars lazy execution and not require any data conversion.
Package: polars-cli
Polars CLIThe Polars command line interface provides a convenient way to execute SQL commands using Polars as a backend.InstallationThe recommended way to install the Polars CLI is by usingpip:pipinstallpolars-cliThis will install a pre-compiled binary and make it available on your path underpolars.
If you do not have Python available, you can download a suitable binary from the most recentGitHub release.Alternatively, you can install the Polars CLI usingcargo, which will compile the code from scratch:cargoinstall--lockedpolars-cliUsageRunningpolarswithout any arguments will start an interactive shell in which you can run SQL commands.$polars
PolarsCLIversion0.4.0
Type.helpforhelp.

>>select*FROMread_csv('examples/datasets/foods.csv');┌────────────┬──────────┬────────┬──────────┐
│category┆calories┆fats_g┆sugars_g│
│---┆---┆---┆---│
│str┆i64┆f64┆i64│
╞════════════╪══════════╪════════╪══════════╡
│vegetables┆45┆0.5┆2│
│seafood┆150┆5.0┆0│
│meat┆100┆5.0┆0│
│fruit┆60┆0.0┆11│
│…┆…┆…┆…│
│seafood┆200┆10.0┆0│
│seafood┆200┆7.0┆2│
│fruit┆60┆0.0┆11│
│meat┆110┆7.0┆0│
└────────────┴──────────┴────────┴──────────┘Alternatively, SQL commands can be piped directly into the Polars CLI.$echo"SELECT category FROM read_csv('examples/datasets/foods.csv')"|polars
┌────────────┐
│category│
│---│
│str│
╞════════════╡
│vegetables│
│seafood│
│meat│
│fruit│
│…│
│seafood│
│seafood│
│fruit│
│meat│
└────────────┘FeaturesWhen compiling the Polars CLI from source, the following features can be enabled:FeatureDescriptiondefaultThe default feature set that includes all other features.highlightProvides syntax highlightingparquetEnables reading and writing of Apache Parquet files.jsonEnables reading and writing of JSON files.ipcEnables reading and writing of IPC/Apache Arrow files
Package: polars-distance
Hellooo :)This plugin is a work-in progress, main goal is to provide distance metrics on list, arrays and string datatypes.The docs can be found here:https://ion-elgreco.github.io/polars-distance/Examplesimportpolarsimportpolars_distanceasplddf=pl.DataFrame({"foo":"hello","bar":"hella world"})df.select(pld.col("foo").dist_str.hamming('bar').alias('dist'))┌──────┐│dist││---││u32│╞══════╡│7│└──────┘df.select(pld.col('foo').dist_str.levenshtein('bar').alias('dist'))┌──────┐│dist││---││u32│╞══════╡│6│└──────┘df=pl.DataFrame({"arr":[[1,2,10]],"arr2":[[2,5,9]],},schema={"arr":pl.Array(inner=pl.Float64,width=3),"arr2":pl.Array(inner=pl.Float64,width=3),},)df.select(pld.col('arr').dist_arr.euclidean('arr2').alias('dist'))shape:(1,1)┌──────────┐│dist││---││f64│╞══════════╡│3.316625│└──────────┘
Package: polars_evm
Polars EVMPolars EVM adds theevmnamespace to polars on dataframes, lazyframes, series, and expressions.This namespace has lots of functions for processing EVM data:binary ↔ hex conversionskeccakabi encoding [TODO]rlp encoding [TODO]Installationpip install polars_evmUsageJust importpolars_evmand then theevmnamespace will be registered to polars.importpolarsasplimportpolars_evmaddresses=[b'\xda\xc1\x7f\x95\x8d.\xe5#\xa2b\x06\x99E\x97\xc1=\x83\x1e\xc7',b'\xa0\xb8i\x91\xc6!\x8b6\xc1\xd1\x9dJ.\x9e\xb0\xce6\x06\xebH',b'_\x98\x80ZN\x8b\xe2U\xa3(\x80\xfd\xec\x7fg(\xc6V\x8b\xa0']series=pl.Series('address',addresses)df=pl.DataFrame(series)print('hex series:',series.evm.binary_to_hex())print('hex df:',df.evm.binary_to_hex())print('hex expr:',df.select(pl.col('address').evm.binary_to_hex()))output:hexseries:shape:(3,)Series:'address'[str]["0xdac17f958d2e…"0xa0b86991c621…"0x5f98805a4e8b…]hex df: shape: (3, 1)┌───────────────────────────────────┐│ address                           ││ ---                               ││ str                               │╞═══════════════════════════════════╡│ 0xdac17f958d2ee523a2206206994597… ││ 0xa0b86991c6218b36c1d19d4a2e9eb0… ││ 0x5f98805a4e8be255a32880fdec7f67… │└───────────────────────────────────┘hex expr: shape: (3, 1)┌───────────────────────────────────┐│ literal                           ││ ---                               ││ str                               │╞═══════════════════════════════════╡│ 0xdac17f958d2ee523a2206206994597… ││ 0xa0b86991c6218b36c1d19d4a2e9eb0… ││ 0x5f98805a4e8be255a32880fdec7f67… │└───────────────────────────────────┘List of namespace entries# DataFrame namespacedf.evm.binary_to_hex(prefix=True,columns=None)df.evm.hex_to_binary(prefix=True,columns=None)# LazyFrame namespacelf.evm.binary_to_hex(prefix=True,columns=None)lf.evm.hex_to_binary(prefix=True,columns=None)# Series namespaceseries.evm.binary_to_hex(prefix=True)series.evm.hex_to_binary(prefix=True)series.evm.keccak(output='hex',text=False)# Expression namespacepl.Expr.evm.binary_to_hex(prefix=True)pl.Expr.evm.hex_to_binary(prefix=True)pl.Expr.evm.keccak(output='hex',text=False)Additional utilitiesBeyond theevmnamespace,polars_evmhas the following utilities:set_column_display_width(): set display width so that it fully displays tx hashes in jupyter notebooks and other printoutsTODOuse efficient rust implementations where possibleabi encodingrlp encoding
Package: polars-fuzzy-match
Polars Fuzzy MatchingInstallationFirst install maturin:pip install maturinTo installpolars-fuzzy-match, clone the repo andcdinto it:git clone git@github.com:bnm3k/polars-fuzzy-match.git
cd polars-fuzzy-matchFrom there, build it:maturin develop --releaseBasic ExampleWith both the plugin and polars installed, start as follows:importpolarsasplfrompolars_fuzzy_matchimportfuzzy_match_scoredf=pl.DataFrame({'strs':['foo','foo quz BAR','baaarfoo','quz'],})pattern='bar'out=df.with_columns(score=fuzzy_match_score(pl.col('strs'),pattern,))print(out)This outputs:shape: (4, 2)
┌─────────────┬───────┐
│ strs        ┆ score │
│ ---         ┆ ---   │
│ str         ┆ u32   │
╞═════════════╪═══════╡
│ foo         ┆ null  │
│ foo quz BAR ┆ 88    │
│ baaarfoo    ┆ 74    │
│ quz         ┆ null  │
└─────────────┴───────┘When there is no match, score isnull. When the pattern matches the value in
the given column, score is non-null. The higher the score, the closer the value
is to the pattern. Therefore, we can filter out values that do not match and
order by score:pattern='bar'out=(df.with_columns(score=fuzzy_match_score(pl.col('strs'),pattern,)).filter(pl.col('score').is_not_null()).sort(by='score',descending=True))print(out)This outputs:shape: (2, 2)
┌─────────────┬───────┐
│ strs        ┆ score │
│ ---         ┆ ---   │
│ str         ┆ u32   │
╞═════════════╪═══════╡
│ foo quz BAR ┆ 88    │
│ baaarfoo    ┆ 74    │
└─────────────┴───────┘Fzf-style search syntaxThis plugin supports Fzf-style search syntax for the pattern. It's worth noting
that this section is taken almost verbatim from the Fzf README:PatternMatch typeDescriptionbarfuzzyitems that fuzzy matchbare.g. 'bXXaXXr''foosubstring exact matchitems that includewilde.g. 'is foo ok'^musicprefix exact matchitems that start withmusic.mp3$suffix exact matchitems that end with.mp3!fireinverse exact matchitems that do not includefire!^musicinverse prefix exact matchitems that do not start withmusic!.mp3$inverse suffix exact matchitems that do not end with.mp3CreditsMarco Gorelli's Tutorial on writing Polars Plugin. Seehere.The Helix Editor team for theNucleo fuzzy matching library.
Package: polars-hash
This plugin provides stable hashing functionality across different polars versions.ExamplesCryptographic Hashersimportpolarsimportpolars_hashasplhdf=pl.DataFrame({"foo":["hello_world"]})result=df.select(plh.col('foo').chash.sha256())print(result)┌──────────────────────────────────────────────────────────────────┐│foo││---││str│╞══════════════════════════════════════════════════════════════════╡│35072c1ae546350e0bfa7ab11d49dc6f129e72ccd57ec7eb671225bbd197c8f1│└──────────────────────────────────────────────────────────────────┘Non-cryptographic Hashersdf=pl.DataFrame({"foo":["hello_world"]})result=df.select(plh.col('foo').nchash.wyhash())print(result)┌──────────────────────┐│foo││---││u64│╞══════════════════════╡│16737367591072095403│└──────────────────────┘Geo Hashersdf=pl.DataFrame({"coord":[{"longitude":-120.6623,"latitude":35.3003}]},schema={"coord":pl.Struct([pl.Field("longitude",pl.Float64),pl.Field("latitude",pl.Float64)]),},)df.with_columns(plh.col('coord').geohash.from_coords().alias('geohash'))shape:(1,2)┌─────────────────────┬────────────┐│coord┆geohash││---┆---││struct[2]┆str│╞═════════════════════╪════════════╡│{-120.6623,35.3003}┆9q60y60rhs│└─────────────────────┴────────────┘pl.select(pl.lit('9q60y60rhs').geohash.to_coords().alias('coordinates'))shape:(1,1)┌───────────────────────┐│coordinates││---││struct[2]│╞═══════════════════════╡│{-120.6623,35.300298}│└───────────────────────┘Create hash from multiple columnsdf=pl.DataFrame({"foo":["hello_world"],"bar":["today"]})result=df.select(plh.concat_str('foo','bar').chash.sha256())
Package: polars-partitions
polars_partitionsPythonpip install polars_partitionsDescriptionThis library is not a replacement forPolars.
The main goal is to improve the work (write/read/filter) with partitions by creating a Table Of Contents file (hereinafter referred to as "TOC").Write Partitionpolars_parquet.wr_partition(df: DataFrame,columns: array | string,output_path: str)ParametersdfPolars DataFramecolumnsArray of columns on which to create partitionsoutput_pathPath to save toExample 🤔🤔🤔importpolars_partitionsasppfromdatetimeimportdateimportpolarsaspl# Create a test datasetdf=pl.DataFrame({'col1':[date(2024,1,1),date(2024,1,1),date(2024,1,2),date(2024,1,2),date(2024,1,2),date(2024,1,3),date(2024,1,3),date(2024,1,3)],'col2':['A2','A2','A2','A2','A2','A2','B2','B2','B2','B2'],'col3':[1,2,3,4,5,6,7,8]})path='./your_path_where_your_partitions'# Which columns are partitioned bycolumns=['col1','col2']ep=pp.EasyPartition(path)# Write the partitionsep.write_data(df,columns)# Output:# ./your_path_where_your_partitions/toc.parquet - done!Write TOCpolars_parquet.wr_toc()polars_parquet.wr_toc(df: DataFrame on which the partitions are based,columns: array | string,output_path: str)ParametersdfDictionary, where the key is the column and the array is the valuescolumnsArray of columns to create partitions foroutput_pathPath to save toReading TOCpolars_parquet.rd_toc()polars_parquet.rd_toc(output_path: DataFrame,filters: dict = None,btwn: str = None)Parametersoutput_pathPath where to save.filtersDictionary, where the key is the column and the array is the valuesbtwnWorks in conjunction withfilters. It takes as input thecolumn nameon which to apply thebetweenfilter. It takes the first two values from the filters(array).Example 🤔🤔🤔ep.get_toc()# Output:shape:(4,2)┌────────────┬──────┐│col1┆col2││---┆---││date┆str│╞════════════╪══════╡│2024-01-02┆A2││2024-01-02┆B2││2024-01-01┆A2││2024-01-03┆B2│└────────────┴──────┘Read Partitionpolars_parquet.rd_partition()polars_parquet.rd_partition(output_path: str,columns: array | string = "*",filters: dict = None,btwn: str = None)→ LazyFrameParametersoutput_pathPath to the parquet file or to the partitions foldercolumnsArray of columns to returnfiltersDictionary where the key is the column and the array is the valuesbtwnWorks in conjunction withfilters. It takes as input thecolumn nameon which to apply thebetweenfilter. It takes the first two values from the filters(array).Example 🤔🤔🤔filters={'col1':[date(2024,1,1),date(2024,1,3)]}withpl.StringCache():df=ep.get_data(filters=filters,between='col1',columns=['col1','col3']).collect()df# Output:shape:(8,2)┌────────────┬──────┐│col1┆col3││---┆---││str┆i64│╞════════════╪══════╡│2024-01-02┆3││2024-01-02┆4││2024-01-02┆5││2024-01-01┆1││2024-01-01┆2││2024-01-03┆6││2024-01-03┆7││2024-01-03┆8│└────────────┴──────┘
Package: polars-pc
Polars-pcRegisters pyarrow-compute functions to expressions namespace under "pc". This isn't a rust port, it just calls them as they are withmap_batches. All the methods that only have a single input are dynamically loaded. For instance:df.with_columns(c=pl.col('a').pc.cumulative_sum())Methods which take two inputs are statically loaded, right now onlyindex_inis loaded and that works likedf.with_columns(c=pl.col('a').pc.index_in('b'))Installpip install polars-pcUsageimport polars_pc
import polars as pl
df=pl.DataFrame({
    'a':[1,2,2,3,4],
    'b':[1,1,1,3,3]
})
df.with_columns(c=pl.col('a').pc.cumulative_sum())
df.with_columns(c=pl.col('a').pc.index_in('b'))
Package: polars-reverse-geocode
Polars-Reverse-GeocodePolars plugin based onhttps://github.com/gx0r/rrgeo.rrgeo takes a latitude and longitude as input and returns the closest city, country, latitude, and longitude, using a k-d tree to efficiently find the nearest neighbour based on a known list of locations. This can be useful if you need to reverse geocode a large number of coordinates quickly, or just need the rough location of coordinates but don't want the expense or complication of an online reverse geocoder.Installationpip install polars-reverse-geocodeUsage exampleimportpolarsasplfrompolars_reverse_geocodeimportreverse_geocodedf=pl.DataFrame({'lat':[37.7749,51.01,52.5],'lon':[-122.4194,-3.9,-.91]})print(df.with_columns(city=reverse_geocode('lat','lon')))shape: (3, 3)
┌─────────┬───────────┬───────────────────┐
│ lat     ┆ lon       ┆ city              │
│ ---     ┆ ---       ┆ ---               │
│ f64     ┆ f64       ┆ str               │
╞═════════╪═══════════╪═══════════════════╡
│ 37.7749 ┆ -122.4194 ┆ San Francisco     │
│ 51.01   ┆ -3.9      ┆ South Molton      │
│ 52.5    ┆ -0.91     ┆ Market Harborough │
└─────────┴───────────┴───────────────────┘
Package: polars-splines
Polars splinesAn simpleextension pluginforpy-polars, that interfaces with the Rust cargosplines, for spline interpolation.UsageThe expression plugin addssplinesto the expression namespace. This contains the methodsplinewhich acts on aSeriesofStructtype. The two fields corresponds to the (x, y) pairs to be interpolated. Thesplinemethod accepts a keyword argumentxifor the interpolation points.For example,importpolarsasplimportpolars_splinesimportnumpyasnpx=pl.Series("x",np.linspace(0,1,100))y=pl.Series("y",np.sin(x))df=pl.DataFrame({"x":x,"y":y})xi=pl.Series("xi",np.linspace(0,1,1000))dfi=df.select(pl.struct("x","y").splines.spline(list(xi),fill_value=0.0).alias("yi")).with_columns(xi)
Package: polars-splitters
polars-splittersPolars-based splitter functionalities for polars LazyFrames and DataFrames similar tosklearn.model_selection.train_test_splitandsklearn.model_selection.StratifiedKFold.featuressplit_into_train_evalsplit_into_k_foldsinstallationpipinstallpolars-splittersusageimportpolarsasplfrompolars_splittersimportsplit_into_train_eval,split_into_k_foldsdf=pl.DataFrame({"feature_1":[1,2,3,4,5,6,7,8,9,10,11],"treatment":[0,0,0,0,1,1,1,1,1,1,1],"outcome":[0,0,0,0,0,0,0,1,1,1,1],})df_train,df_test=split_into_train_eval(df,eval_rel_size=0.3,stratify_by=["treatment","outcome"],shuffle=True,validate=True,as_lazy=False,rel_size_deviation_tolerance=0.1,)folds=split_into_k_folds(df,k=3,stratify_by=["treatment","outcome"],shuffle=False,as_lazy=False)
Package: polars-streaming
polars-streamingThis library helps to process streaming data using Polars.Installationpipinstallpolars-streamingInstall from sourcesAlternatively, you can also clone the latest version from therepositoryand install it directly from the source code:pipinstall-e.Quick tourSocket>>>frompolars_streamingimportStreamProcessor>>>s=StreamProcessor()>>>s.readStream.format('socket').options({'host':'localhost','port':12345}).load()>>>deftransformation(df):>>># Add your transformation code here>>>df=df.sum()# For example purpose, I am calculating the sum.>>>returndf# Return the transformed dataframe>>>s.add_transform(transformation)>>>s.writeStream.format('console').trigger('3 seconds')>>>s.start()Kafka>>>frompolars_streamingimportStreamProcessor>>>s=StreamProcessor()>>>s.readStream.format('kafka').options({'kafka.bootstrap.servers':'localhost','subscribe':'topic_name','startingOffsets':'earliest','kafka.group.id':'g1'}).load()>>>deftransformation(df):>>># Add your transformation code here>>>df=df.sum()# For example purpose, I am calculating the sum.>>>returndf# Return the transformed dataframe>>>s.add_transform(transformation)>>>s.writeStream.format('console').trigger('10 seconds')>>>s.start()File Sources>>>frompolars_streamingimportStreamProcessor>>>s=StreamProcessor()>>>s.readStream.format('csv').load('read_path_of_file_source')# Reads the csv file from the path once it is created>>>deftransformation(df):>>># Add your transformation code here>>>df=df.sum()# For example purpose, I am calculating the sum.>>>returndf# Return the transformed dataframe>>>s.add_transform(transformation)>>>s.writeStream.option('path','write_path').format('avro')# Write the processed data to the write path in avro format>>>s.start()SourcesSocketFile SourcesCSVJSONAVROPARQUETKafkaSinksConsoleFile SourcesCSVJSONAVROPARQUETMongoDBElasticSearch
Package: polars-ta
polars_ta基于polars的算子库。实现量化投研中常用的技术指标、数据处理等函数。对于不易翻译成Expr的库（如：TA-Lib）也提供了函数式调用的封装安装在线安装pip install -i https://pypi.org/simple --upgrade polars_ta  # 官方源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade polars_ta  # 国内镜像源源码安装git clone --depth=1 https://github.com/wukan1986/polars_ta.git
cd polars_ta
python -m build
cd dist
pip install polars_ta-0.1.2-py3-none-any.whlTA-Lib安装Windows用户不会安装可从https://github.com/cgohlke/talib-build/releases下载对应版本whl文件使用方法参考examples目录即可，例如：# 如果需要在`expr_codegen`中使用，需要有`ts_`等前权，这里导入提供了前缀frompolars_ta.prefix.tdximport*# 导入wq公式frompolars_ta.prefix.wqimport*# 演示生成大量指标df=df.with_columns([# 从wq中导入指标*[ts_returns(CLOSE,i).alias(f'ROCP_{i:03d}')foriin(1,3,5,10,20,60,120)],*[ts_mean(CLOSE,i).alias(f'SMA_{i:03d}')foriin(5,10,20,60,120)],*[ts_std_dev(CLOSE,i).alias(f'STD_{i:03d}')foriin(5,10,20,60,120)],*[ts_max(HIGH,i).alias(f'HHV_{i:03d}')foriin(5,10,20,60,120)],*[ts_min(LOW,i).alias(f'LLV_{i:03d}')foriin(5,10,20,60,120)],# 从tdx中导入指标*[ts_RSI(CLOSE,i).alias(f'RSI_{i:03d}')foriin(6,12,24)],])设计原则调用方法由成员函数换成独立函数。输入输出使用Expr，避免使用Series优先实现wq公式，它仿WorldQuant Alpha公式，与官网尽量保持一致。如果部分功能实现在此更合适将放在此处其次实现ta公式，它相当于TA-Lib的polars风格的版本。优先从wq中导入更名最后实现tdx公式，它也是优先从wq和ta中导入talib的函数名与参数与原版TA-Lib完全一致如果出现了命名冲突，建议调用优先级为wq、ta、tdx、talib。因为优先级越高，实现方案越接近于Expr指标区别请参考compare空值处理请参考nan_to_nullTA-Lib封装的演化Expr.map_batches可以实现调用第三方库，如TA-Lib, bottleneck。但因为对输入与输出格式有要求，所以还需要用函数对第三方API封装一下。输入输出都只能是一列，如要支持多列需转换成pl.Struct。事后pl.Struct要拆分需使用unnest输出必须是pl.Series参数多，代码长。开始使用register_expr_namespace来简化代码实现代码helper.py使用演示demo_ta1.py优点：使用简单不足：成员函数调用模式不便于输入到遗传算法中进行因子挖掘不足：__getattribute__动态方法调用非常灵活，但失去了IDE智能提示前缀表达式。将所有的成员函数都转换成公式实现代码wrapper.py使用演示demo_ta2.py优点：可以输入到遗传算法不足：__getattribute__动态方法调用非常灵活，但失去了IDE智能提示代码自动生成。实现代码codegen_talib2.py生成结果__init__.py使用演示demo_ta3.py优点：即可以输入到遗传算法，IDE还有智能提示开发调试git clone --depth=1 https://github.com/wukan1986/polars_ta.git
cd polars_ta
pip install -e .注意：如果你在ta或tdx中添加了新的函数，请再运行tools下的prefix_ta.py或prefix_tdx.py，用于生成对应的前缀文件。前缀文件方便在expr_codegen中使用参考https://github.com/pola-rs/polarshttps://github.com/TA-Lib/ta-libhttps://github.com/twopirllc/pandas-tahttps://github.com/bukosabino/tahttps://github.com/peerchemist/fintahttps://github.com/wukan1986/ta_cnhttps://support.worldquantbrain.com/hc/en-us/community/posts/20278408956439-从价量看技术指标总结-Technical-Indicator-
Package: polarstypes
polars-typesThis library is centered around down casting datatypes in python polars. hopefully this kind of feature will be standard eventually
The library can help polars users achieve the memory compression offered by the underlying
data format used for python-polars - a columnar data storeThere are so far two key functionsOne function that identifies integer ranges and selects the appropriate integer datatype (bit resolution and signedness)
One function that converts non-unique string columns to categorical columnsFuture:itentify non-repeating values as attributes or as type literal