违心°

文章 评论 浏览 33

违心° 2025-02-16 15:41:53

我也对此感到好奇,但从略有不同的角度来看。我试图避免直接从MSAL中乱扔代码库,以防我们想在某个时候交换身份提供商。这样做的主要方法是将钩子用作抽象层,例如通过该钩子而不是MSAL组件库本身揭示iShauthenticatientical层。

UseAuth Hook将直接使用MSAL包。但是,对于包装器组件,我认为我们只需要创建一个单独的组件,该组件要么返回MSALPROVIDER或您选择的模拟Auth提供商。由于MSALPROVIDER在引擎盖下使用Usecontext,因此我认为您不需要在另一个上下文提供商中包装它。

希望这些想法在您通过做到这一点的方式思考时会有所帮助。知道这不是您问题的直接答案。

I am also curious about this, but from a slightly different perspective. I am trying to avoid littering the code base with components directly from msal in case we want to swap out identity providers at some point. The primary way to do this is to use a hook as an abstraction layer such as exposing isAuthenticated through that hook rather than the msal component library itself.

The useAuth hook would use the MSAL package directly. For the wrapper component however, I think we have to just create a separate component that either returns the MsalProvider OR a mocked auth provider of your choice. Since MsalProvider uses useContext beneath the hood I don't think you need to wrap it in another context provider.

Hope these ideas help while you are thinking through ways to do this. Know this isn't a direct answer to your question.

测试MSAL React应用程序时嘲笑身份验证

违心° 2025-02-16 12:50:30

我使用Xamarin Android出现了类似的错误。我通过编辑 androidManifest.xml Microsoft Docs

<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_MAP_IP_KEY"></meta-data>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<!-- Necessary for apps that target Android 9.0 or higher -->
<uses-library android:name="org.apache.http.legacy" android:required="false" />

I got a similar error using Xamarin Android. I fixed by editing AndroidManifest.xml following microsoft docs

<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_MAP_IP_KEY"></meta-data>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<!-- Necessary for apps that target Android 9.0 or higher -->
<uses-library android:name="org.apache.http.legacy" android:required="false" />

googlemaps小部件错误无法检索com.google.android.libraries.consentverifier的标志快照

违心° 2025-02-16 11:43:44

要将某种类型转换为 ctypes 该类型的数组,直接的成语是:

(element_type * num_elements)(*list_of_elements)

在这种情况下:

(c_char_p * len(array))(*array)

请注意,(*array)将数组展开元素作为参数传递,这是初始化数组所需的。

完整示例:

test.c - 验证参数已按预期传递。

#include <stdio.h>

#ifdef _WIN32
#   define API __declspec(dllexport)
#else
#   define API
#endif

API int foo(int numOfProp, const char** propName, const char** propValue) {
    for(int i = 0; i < numOfProp; i++)
        printf("name = %s    value = %s\n", propName[i], propValue[i]);
    return 1;
}

test.py

import ctypes as ct

dll = ct.CDLL('./test')
# Always define .argtypes and .restype to help ctypes error checking
dll.foo.argtypes = ct.c_int, ct.POINTER(ct.c_char_p), ct.POINTER(ct.c_char_p)
dll.foo.restype = ct.c_int

# helper function to build ctypes arrays
def make_charpp(arr):
    return (ct.c_char_p * len(arr))(*(s.encode() for s in arr))

def foo(arr1, arr2):
    if len(arr1) != len(arr2):
        raise ValueError('arrays must be same length')
    return dll.foo(len(arr1) ,make_charpp(arr1), make_charpp(arr2))

foo(['PropName1', 'PropName2'], ['10', '20'])

输出:

name = PropName1    value = 10
name = PropName2    value = 20

To convert a list some type into a ctypes array of that type, the straightforward idiom is:

(element_type * num_elements)(*list_of_elements)

In this case:

(c_char_p * len(array))(*array)

Note that (*array) expands the array as if each individual element was passed as a parameter, which is required to initialize the array.

Full example:

test.c - To verify the parameters are passed as expected.

#include <stdio.h>

#ifdef _WIN32
#   define API __declspec(dllexport)
#else
#   define API
#endif

API int foo(int numOfProp, const char** propName, const char** propValue) {
    for(int i = 0; i < numOfProp; i++)
        printf("name = %s    value = %s\n", propName[i], propValue[i]);
    return 1;
}

test.py

import ctypes as ct

dll = ct.CDLL('./test')
# Always define .argtypes and .restype to help ctypes error checking
dll.foo.argtypes = ct.c_int, ct.POINTER(ct.c_char_p), ct.POINTER(ct.c_char_p)
dll.foo.restype = ct.c_int

# helper function to build ctypes arrays
def make_charpp(arr):
    return (ct.c_char_p * len(arr))(*(s.encode() for s in arr))

def foo(arr1, arr2):
    if len(arr1) != len(arr2):
        raise ValueError('arrays must be same length')
    return dll.foo(len(arr1) ,make_charpp(arr1), make_charpp(arr2))

foo(['PropName1', 'PropName2'], ['10', '20'])

Output:

name = PropName1    value = 10
name = PropName2    value = 20

使用CTYPES在Python中创建一系列指针

违心° 2025-02-16 08:38:49

arrays.deeptostring(arr)仅在一行上打印。

int[][] table = new int[2][2];

要实际获取一个表作为二维表打印的表,我必须这样做:

System.out.println(Arrays.deepToString(table).replaceAll("],", "]," + System.getProperty("line.separator")));

似乎 arrays.deeptostring(arr)方法应该采用一个分隔符字符串,但不幸的是不是。

Arrays.deepToString(arr) only prints on one line.

int[][] table = new int[2][2];

To actually get a table to print as a two dimensional table, I had to do this:

System.out.println(Arrays.deepToString(table).replaceAll("],", "]," + System.getProperty("line.separator")));

It seems like the Arrays.deepToString(arr) method should take a separator string, but unfortunately it doesn't.

什么是打印Java数组的最简单方法?

违心° 2025-02-16 08:28:20

对于测试简单对象,请使用:

if (obj[x] !== undefined)

如果您不知道它是哪种对象类型,请使用:

if (obj.hasOwnProperty(x))

所有其他选项都较慢...

详细介绍了

Node.js下100,000,000个周期的性能评估,以便在此处建议的五个选项

function hasKey1(k,o) { return (x in obj); }
function hasKey2(k,o) { return (obj[x]); }
function hasKey3(k,o) { return (obj[x] !== undefined); }
function hasKey4(k,o) { return (typeof(obj[x]) !== 'undefined'); }
function hasKey5(k,o) { return (obj.hasOwnProperty(x)); }

:评估告诉我们,除非我们特别想检查对象的原型链以及对象本身,我们不应使用常见的形式

if (X in Obj)...

它慢于2至6倍,取决于用例

hasKey1 execution time: 4.51 s
hasKey2 execution time: 0.90 s
hasKey3 execution time: 0.76 s
hasKey4 execution time: 0.93 s
hasKey5 execution time: 2.15 s

底线,如果您的OBJ不一定是一个简单的对象,并且您希望避免检查对象的原型链并确保直接obj直接拥有x,请使用 if(obj.hasownproperty(x)) )...

否则,使用简单对象而不担心对象的原型链时,使用 if(typeof(obj [x])!=='undefined')... 是最安全,最快的方法。

如果您将简单的对象用作哈希表,并且永远不会做任何问题,则我会使用如果(obj [x])... ,因为我发现它更可读。

For testing simple objects, use:

if (obj[x] !== undefined)

If you don't know what object type it is, use:

if (obj.hasOwnProperty(x))

All other options are slower...

Details

A performance evaluation of 100,000,000 cycles under Node.js to the five options suggested by others here:

function hasKey1(k,o) { return (x in obj); }
function hasKey2(k,o) { return (obj[x]); }
function hasKey3(k,o) { return (obj[x] !== undefined); }
function hasKey4(k,o) { return (typeof(obj[x]) !== 'undefined'); }
function hasKey5(k,o) { return (obj.hasOwnProperty(x)); }

The evaluation tells us that unless we specifically want to check the object's prototype chain as well as the object itself, we should not use the common form:

if (X in Obj)...

It is between 2 to 6 times slower depending on the use case

hasKey1 execution time: 4.51 s
hasKey2 execution time: 0.90 s
hasKey3 execution time: 0.76 s
hasKey4 execution time: 0.93 s
hasKey5 execution time: 2.15 s

Bottom line, if your Obj is not necessarily a simple object and you wish to avoid checking the object's prototype chain and to ensure x is owned by Obj directly, use if (obj.hasOwnProperty(x))....

Otherwise, when using a simple object and not being worried about the object's prototype chain, using if (typeof(obj[x]) !== 'undefined')... is the safest and fastest way.

If you use a simple object as a hash table and never do anything kinky, I would use if (obj[x])... as I find it much more readable.

如何检查对象是否在JavaScript中具有特定属性?

违心° 2025-02-16 07:47:08

您正在使用 tag_name ,这两个评论和答复都是相同的。因此,导致 2个节点(可能有很多取决于您的 html-dom )。

如果您想区分节点,我会发现 data-service-review-date-time-ago 属性是唯一的。

因此,将其更改为CSS/XPath将完成工作。

css: 时间[data-service-review-date-date time-ago]

xpath: // time [@data-service -review-date time-ago]

您可以使用 driver.find_element(by.xpath,“ // time [@dation-service-review-date-date-time-ago)调用它们)< /code>或 driver.find_element(by.css_selector,“ time [data-service-review-date-time-ago]”)

。 /代码>将返回Web元素列表,如果您针对第一个节点,则可能要使用 find_element

You are using TAG_NAME which is the same for both reviews and replies. Therefore results in 2 nodes, (could be many however that depends on your HTML-DOM).

If you want to differentiate the nodes, I see that data-service-review-date-time-ago attribute is unique for review.

Hence changing that to either CSS/XPATH would get the job done.

CSS: time[data-service-review-date-time-ago]

XPATH: //time[@data-service-review-date-time-ago]

You can call them using driver.find_element(By.XPATH, "//time[@data-service-review-date-time-ago]") or driver.find_element(By.CSS_SELECTOR, "time[data-service-review-date-time-ago]") etc.

Also, note that you are using find_elements which would return a list of web elements, may be you wanted to use find_element if you were targeting the first node.

使用硒来找到评论的日期,而不是答复,Python

违心° 2025-02-16 02:52:19

根据上述答案,我试图提出一个版本的下个月和最后一天的第一天。让我知道您的想法:

月开始:

Get-Date -Format "yyyy-MM-ddT00:00:00Z" -Date ([datetime](Get-Date -Day 1).AddMonths(1))

输出:2022-07-01T00:00:00:00Z

月末:

Get-Date -Format "yyyy-MM-ddT23:59:59Z"-Date (([datetime](Get-Date -Day 1).AddMonths(2)).AddDays(-1))

输出:2022-07-31T23:59:59Z

Based on the above answer, i tried to come up with a version of getting the first day of the next month and the last day. Let me know your thoughts:

Beggining of month:

Get-Date -Format "yyyy-MM-ddT00:00:00Z" -Date ([datetime](Get-Date -Day 1).AddMonths(1))

Output: 2022-07-01T00:00:00Z

End of month:

Get-Date -Format "yyyy-MM-ddT23:59:59Z"-Date (([datetime](Get-Date -Day 1).AddMonths(2)).AddDays(-1))

Output: 2022-07-31T23:59:59Z

如何将未来日期转换为Yyyy-MM-DDT00:00:00:00Z格式使用PowerShell

违心° 2025-02-15 15:40:28

这是@Steven Rumbalski的答案 验证 entrac> widget值,通过追踪到 StringVar - 我已经通过将其编辑到位,在某种程度上进行了调试并改进。

下面的版本将所有内容都放入 stringvar subclass 以封装更好的事情,更重要的是,允许同一时间同时存在多个独立实例,而不会彼此干扰 - 他的实现一个潜在的问题,因为它利用函数属性而不是实例属性,这些属性与全局变量基本相同,并且在这种情况下可能会导致问题。

try:
    from tkinter import *
except ImportError:
    from Tkinter import *  # Python 2


class ValidateFloatVar(StringVar):
    """StringVar subclass that only allows valid float values to be put in it."""

    def __init__(self, master=None, value=None, name=None):
        StringVar.__init__(self, master, value, name)
        self._old_value = self.get()
        self.trace('w', self._validate)

    def _validate(self, *_):
        new_value = self.get()
        try:
            new_value == '' or float(new_value)
            self._old_value = new_value
        except ValueError:
            StringVar.set(self, self._old_value)


root = Tk()
ent = Entry(root, textvariable=ValidateFloatVar(value=42.0))
ent.pack()
ent.focus_set()
ent.icursor(END)

root.mainloop()

Here's an improved version of @Steven Rumbalski's answer of validating the Entry widgets value by tracing changes to a StringVar — which I have already debugged and improved to some degree by editing it in place.

The version below puts everything into a StringVar subclass to encapsulates what's going on better and, more importantly allow multiple independent instances of it to exist at the same time without interfering with each other — a potential problem with his implementation because it utilizes function attributes instead of instance attributes, which are essentially the same thing as global variables and can lead to problems in such a scenario.

try:
    from tkinter import *
except ImportError:
    from Tkinter import *  # Python 2


class ValidateFloatVar(StringVar):
    """StringVar subclass that only allows valid float values to be put in it."""

    def __init__(self, master=None, value=None, name=None):
        StringVar.__init__(self, master, value, name)
        self._old_value = self.get()
        self.trace('w', self._validate)

    def _validate(self, *_):
        new_value = self.get()
        try:
            new_value == '' or float(new_value)
            self._old_value = new_value
        except ValueError:
            StringVar.set(self, self._old_value)


root = Tk()
ent = Entry(root, textvariable=ValidateFloatVar(value=42.0))
ent.pack()
ent.focus_set()
ent.icursor(END)

root.mainloop()

交互式验证TKINTER中的输入小部件内容

违心° 2025-02-15 08:15:08

可以在聚类的索引视图上创建一个唯一的约束,

您可以创建这样的视图:

CREATE VIEW dbo.VIEW_OfYourTable WITH SCHEMABINDING AS
SELECT YourUniqueColumnWithNullValues FROM dbo.YourTable
WHERE YourUniqueColumnWithNullValues IS NOT NULL;

以及这样的唯一约束:

CREATE UNIQUE CLUSTERED INDEX UIX_VIEW_OFYOURTABLE 
  ON dbo.VIEW_OfYourTable(YourUniqueColumnWithNullValues)

It is possible to create a unique constraint on a Clustered Indexed View

You can create the View like this:

CREATE VIEW dbo.VIEW_OfYourTable WITH SCHEMABINDING AS
SELECT YourUniqueColumnWithNullValues FROM dbo.YourTable
WHERE YourUniqueColumnWithNullValues IS NOT NULL;

and the unique constraint like this:

CREATE UNIQUE CLUSTERED INDEX UIX_VIEW_OFYOURTABLE 
  ON dbo.VIEW_OfYourTable(YourUniqueColumnWithNullValues)

如何创建一个允许零的独特约束?

违心° 2025-02-14 19:13:10

尝试使用此类:

class AddressTile extends StatelessWidget {
  final SystemData systemData;
  final int index;
  const AddressTile({required this.systemData, required this.index, Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (systemData.addresses == null || systemData.addresses!.length < index) {
      return Container();
    }
    Address address = systemData.addresses![index];
    
    return Container(
      padding: const EdgeInsets.symmetric(
        horizontal: 10,
      ),
      width: MediaQuery.of(context).size.width,
      margin: const EdgeInsets.only(bottom: 12, top: 12),
      child: Container(
        padding: const EdgeInsets.all(5),
        //  width: SizeConfig.screenWidth * 0.78,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(16),
            color: Theme.of(context).backgroundColor),
        child: Row(children: [
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const Icon(
                      Icons.location_pin,
                      //size: 30,
                    ),
                    const SizedBox(width: 4),
                    Flexible(
                      child: AutoSizeText(
                        address.line1Address!,
                        style: const TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ],
                ),
                const SizedBox(
                  height: 10,
                ),
                Container(
                  padding: const EdgeInsets.only(left: 20),
                  child: Column(
                    children: [
                      AutoSizeText(
                        '${address.line2Address!} ${address.township!} ${address.state!} ${address.country!} ${address.postalCode}',
                        //maxLines: 1,
                        style: const TextStyle(fontSize: 16),
                      ),
                    ],
                  ),
                ),
                const SizedBox(
                  height: 10,
                ),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const Icon(
                      Icons.phone_outlined,
                      //size: 30,
                    ),
                    const SizedBox(width: 4),
                    Row(
                      children: [
                        //const SizedBox(height: 30),
                        TextButton(
                          style: TextButton.styleFrom(
                            textStyle: const TextStyle(fontSize: 16),
                          ),
                          onPressed: () {
                            launchURL("tel:${address.phone1!}");
                          },
                          child: Text(address.phone1!),
                        ),
                        const SizedBox(height: 10),
                        TextButton(
                          style: TextButton.styleFrom(
                            textStyle: const TextStyle(fontSize: 16),
                          ),
                          onPressed: () {
                            launchURL("tel:${address.phone2!}");
                          },
                          child: Text(address.phone2!),
                        ),
                      ],
                    )
                  ],
                ),
                Divider(
                  color: Theme.of(context).scaffoldBackgroundColor,
                  thickness: 2.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    TextButton.icon(
                      onPressed: () {
                        launchURL(systemData.facebook!);
                      },
                      icon: const Icon(Icons.facebook_outlined),
                      label: const AutoSizeText("Facebook"),
                    ),
                    TextButton.icon(
                      onPressed: () {
                        launchURL(systemData.messenger!);
                      },
                      icon: const Icon(Icons.messenger_outline_sharp),
                      label: const AutoSizeText("Chat"),
                    ),
                    TextButton.icon(
                      onPressed: () {
                        launchURL(systemData.youtube!);
                      },
                      icon: const Icon(Icons.videocam),
                      label: const AutoSizeText("Youtube"),
                    ),
                  ],
                )
              ],
            ),
          ),
        ]),
      ),
    );
  }
}

Try using this class:

class AddressTile extends StatelessWidget {
  final SystemData systemData;
  final int index;
  const AddressTile({required this.systemData, required this.index, Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (systemData.addresses == null || systemData.addresses!.length < index) {
      return Container();
    }
    Address address = systemData.addresses![index];
    
    return Container(
      padding: const EdgeInsets.symmetric(
        horizontal: 10,
      ),
      width: MediaQuery.of(context).size.width,
      margin: const EdgeInsets.only(bottom: 12, top: 12),
      child: Container(
        padding: const EdgeInsets.all(5),
        //  width: SizeConfig.screenWidth * 0.78,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(16),
            color: Theme.of(context).backgroundColor),
        child: Row(children: [
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const Icon(
                      Icons.location_pin,
                      //size: 30,
                    ),
                    const SizedBox(width: 4),
                    Flexible(
                      child: AutoSizeText(
                        address.line1Address!,
                        style: const TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ],
                ),
                const SizedBox(
                  height: 10,
                ),
                Container(
                  padding: const EdgeInsets.only(left: 20),
                  child: Column(
                    children: [
                      AutoSizeText(
                        '${address.line2Address!} ${address.township!} ${address.state!} ${address.country!} ${address.postalCode}',
                        //maxLines: 1,
                        style: const TextStyle(fontSize: 16),
                      ),
                    ],
                  ),
                ),
                const SizedBox(
                  height: 10,
                ),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const Icon(
                      Icons.phone_outlined,
                      //size: 30,
                    ),
                    const SizedBox(width: 4),
                    Row(
                      children: [
                        //const SizedBox(height: 30),
                        TextButton(
                          style: TextButton.styleFrom(
                            textStyle: const TextStyle(fontSize: 16),
                          ),
                          onPressed: () {
                            launchURL("tel:${address.phone1!}");
                          },
                          child: Text(address.phone1!),
                        ),
                        const SizedBox(height: 10),
                        TextButton(
                          style: TextButton.styleFrom(
                            textStyle: const TextStyle(fontSize: 16),
                          ),
                          onPressed: () {
                            launchURL("tel:${address.phone2!}");
                          },
                          child: Text(address.phone2!),
                        ),
                      ],
                    )
                  ],
                ),
                Divider(
                  color: Theme.of(context).scaffoldBackgroundColor,
                  thickness: 2.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    TextButton.icon(
                      onPressed: () {
                        launchURL(systemData.facebook!);
                      },
                      icon: const Icon(Icons.facebook_outlined),
                      label: const AutoSizeText("Facebook"),
                    ),
                    TextButton.icon(
                      onPressed: () {
                        launchURL(systemData.messenger!);
                      },
                      icon: const Icon(Icons.messenger_outline_sharp),
                      label: const AutoSizeText("Chat"),
                    ),
                    TextButton.icon(
                      onPressed: () {
                        launchURL(systemData.youtube!);
                      },
                      icon: const Icon(Icons.videocam),
                      label: const AutoSizeText("Youtube"),
                    ),
                  ],
                )
              ],
            ),
          ),
        ]),
      ),
    );
  }
}

NULL检查运算符在无效列表上使用的空值

违心° 2025-02-14 11:52:16

尽管对象声明不允许您引用先验属性,但函数声明中的默认值确实如此。

因此,您可以做到这一点:

const foo = ((a=5, b=6, c=a+b) => ({a,b,c}))()

console.log(foo)

Although an object declaration does not allow you to reference prior properties, the default values in a function declaration do.

Therefore, you can do this:

const foo = ((a=5, b=6, c=a+b) => ({a,b,c}))()

console.log(foo)

对象文字 /初始化器中的自我参考

违心° 2025-02-14 09:51:19

使用此行:

 setTimeout(clearInterval(myInterval),2000);

clearInterval(myinterval)部分正在立即执行,而从该调用中的返回值是在计时器的2000毫秒延迟命中后将执行的。

此函数调用的返回值不是 settimeout()需要的第一个参数。它需要功能参考。因此,要进行电话等待计时器的时间,您需要将该调用包装在函数参考中。

setTimeout(function(){ clearInterval(myInterval) },2000);

With this line:

 setTimeout(clearInterval(myInterval),2000);

The clearInterval(myInterval) portion is executing immediately and whatever the return value from that call is is what will be executed after the timer's 2000 ms delay is hit.

The return value from this function call is not what the first argument of setTimeout() requires. It requires a function reference. So to make that call wait for the timer's time, you need to wrap that call in a function reference.

setTimeout(function(){ clearInterval(myInterval) },2000);

我正在尝试使JavaScript函数每50ms每50ms运行一次,但它不起作用

违心° 2025-02-14 06:35:56

基于 @Edchum对他的回答的评论的答案。评论就是这样 -

groupby is notoriously slow and memory hungry, what you could do is sort by column A, then find the idxmin and idxmax (probably store this in a dict) and use this to slice your dataframe would be faster I think 

让我们首先创建一个数据框,在第一列中具有500K类别,而总DF Shape则为2000万。

df = pd.DataFrame(columns=['a', 'b'])
df['a'] = (np.random.randint(low=0, high=500000, size=(20000000,))).astype(str)
df['b'] = list(range(20000000))
print(df.shape)
df.head()
# Sort data by first column 
df.sort_values(by=['a'], ascending=True, inplace=True)
df.reset_index(drop=True, inplace=True)

# Create a temp column
df['temp_idx'] = list(range(df.shape[0]))

# Take all values of b in a separate list
all_values_b = list(df.b.values)
print(len(all_values_b))
# For each category in column a, find min and max indexes
gp_df = df.groupby(['a']).agg({'temp_idx': [np.min, np.max]})
gp_df.reset_index(inplace=True)
gp_df.columns = ['a', 'temp_idx_min', 'temp_idx_max']

# Now create final list_b column, using min and max indexes for each category of a and filtering list of b. 
gp_df['list_b'] = gp_df[['temp_idx_min', 'temp_idx_max']].apply(lambda x: all_values_b[x[0]:x[1]+1], axis=1)

print(gp_df.shape)
gp_df.head()

上面的代码在第一列中需要2分钟的2000万行和500K类别。

Answer based on @EdChum's comment on his answer. Comment is this -

groupby is notoriously slow and memory hungry, what you could do is sort by column A, then find the idxmin and idxmax (probably store this in a dict) and use this to slice your dataframe would be faster I think 

Let's first create a dataframe with 500k categories in first column and total df shape 20 million as mentioned in question.

df = pd.DataFrame(columns=['a', 'b'])
df['a'] = (np.random.randint(low=0, high=500000, size=(20000000,))).astype(str)
df['b'] = list(range(20000000))
print(df.shape)
df.head()
# Sort data by first column 
df.sort_values(by=['a'], ascending=True, inplace=True)
df.reset_index(drop=True, inplace=True)

# Create a temp column
df['temp_idx'] = list(range(df.shape[0]))

# Take all values of b in a separate list
all_values_b = list(df.b.values)
print(len(all_values_b))
# For each category in column a, find min and max indexes
gp_df = df.groupby(['a']).agg({'temp_idx': [np.min, np.max]})
gp_df.reset_index(inplace=True)
gp_df.columns = ['a', 'temp_idx_min', 'temp_idx_max']

# Now create final list_b column, using min and max indexes for each category of a and filtering list of b. 
gp_df['list_b'] = gp_df[['temp_idx_min', 'temp_idx_max']].apply(lambda x: all_values_b[x[0]:x[1]+1], axis=1)

print(gp_df.shape)
gp_df.head()

This above code takes 2 minutes for 20 million rows and 500k categories in first column.

如何将dataframe行分组为pandas groupby中的列表

违心° 2025-02-13 18:40:19

根据不再起作用:

使用ForcenetworkSerializeByMemcpy目前是从此版本开始的方法。我们正在考虑带回旧的行为,该行为允许自己使用固定的字符串。

使用以下结构绕过此问题(CF ):

using System;
using Unity.Collections;
using Unity.Netcode;

public struct NetworkString : INetworkSerializable
{
    private ForceNetworkSerializeByMemcpy<FixedString32Bytes> data;

    public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    {
        serializer.SerializeValue(ref data);
    }

    public override string ToString() => data.Value.ToString();

    public static implicit operator string(NetworkString networkString) => networkString.ToString();
    public static implicit operator NetworkString(string s) => new NetworkString { data = new FixedString32Bytes(s) };
}

According to this thread FixedString32Bytes does not work anymore :

Using ForceNetworkSerializeByMemcpy is currently the way to go starting from this release. We're looking at bringing back the old behaviour which allowed for just using fixed string on its own.

Use the following struct to bypass this issue (cf NEOMORPH_STUDIO_SRL):

using System;
using Unity.Collections;
using Unity.Netcode;

public struct NetworkString : INetworkSerializable
{
    private ForceNetworkSerializeByMemcpy<FixedString32Bytes> data;

    public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    {
        serializer.SerializeValue(ref data);
    }

    public override string ToString() => data.Value.ToString();

    public static implicit operator string(NetworkString networkString) => networkString.ToString();
    public static implicit operator NetworkString(string s) => new NetworkString { data = new FixedString32Bytes(s) };
}

serializeValue不使用fixedString32Bytes值

违心° 2025-02-12 18:42:58

在您的 netlify.toml 中有一个 [functions] 的选项 nater node_node_modules ,它允许您指定节点模块数组以从捆绑包中排除。

以下将忽略所有功能上的模块。

[functions]
  ignored_node_modules = ["aws-sdk"]

或者,您可以按名称来定位特定功能

[functions.render]
  ignored_node_modules = ["aws-sdk"]

,请注意,所有运行节点的lambdas(甚至节点16 lts)仍在使用 aws-sdk (版本2)而不是@aws-aws-sdk (版本3)。

For anyone curious, I discovered this option here< /a>在Netlify CLI源中。

In your netlify.toml there is an undocumented option for [functions] called ignored_node_modules that lets you specify an array of Node modules to exclude from the bundle.

The following will ignore the modules across all functions.

[functions]
  ignored_node_modules = ["aws-sdk"]

Or you can target a specific function by name

[functions.render]
  ignored_node_modules = ["aws-sdk"]

Note that all Lambdas running Node (Even Node 16 LTS) are still using aws-sdk (version 2) and not @aws-sdk (version 3).

For anyone curious, I discovered this option here in the Netlify CLI source.

如何从NetLify函数捆绑包中排除节点模块?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文